Is manual pattern recognition a valid scientific tool if followed up by statistical analysis? Say I have a dataset of some kind, and I am looking through some graphs I have made from it. I notice a pattern, maybe a possible correlation, so I build a computer script or do some spreadsheet-magic to do some statistical work that backs up my findings.
Even though it is really just the testing of a hypothesis, this feels unscientific to me considering that the hypothesis is not the main concern of the study. My question is: is this a common occurrence in academic research, and if so, how is it often carried out/described?
 A: Yes, what you describe is a bad idea because it biases the p-values strongly. As always, there's an xkcd for it, or at least an extreme version of it. However, it does happen and it was a factor in many big cases within the replication crisis in social science, including the work of Brian Wansink and Amy Cuddy. As such, it's also been a motivating factor in the effort to make pre-registration a standard practice in science.
The topic itself has been discussed a tremendous amount in recent years, and you can find more through googling 'p-hacking', 'fishing for significance', or Andrew Gelman's favoured terms 'researcher degrees of freedom' and 'garden of forking paths' (these encompass a great deal more than the behaviour you describe, though).

Note that this does not mean that there's no place for the kinds of exploration you are describing! Exploratory analysis is important, but biases creep in when such exploration is conflated with hypothesis-testing.
Both can be achieved in a valid way, however. Split your dataset beforehand and do your exploration/hypothesis generation on one subset of the data. Once you have developed & refined this into specific hypotheses, you can test them using a separate data subset (or subsets). Or equivalently, collect a new dataset to test the hypotheses you've generated through exploratory analysis of an existing dataset.
Of course, another option is to ditch p-values entirely. Bayesian statistics has much to recommend it, and one advantage is that it's less susceptible to this kind of 'cheating' (loosely speaking). 
A: That's a perfectly reasonable way to generate hypotheses/ideas/things to investigate. 
Where things go wrong is, if you then evaluate this hypothesis on the same data, as if you had had this hypothesis before seeing the data (and even worse if one misleads people in this respect and claims that this had been the pre-specified research question). The clean way to do this, is to generate ideas on one set of data and then to see whether these actually work on another set of data.
