What is the problem with post-hoc testing?

My statistic professor says so, all the books that I look at state it: post-hoc-testing is unscientific. You must derive a hypothesis from theory first, and then collect data and analyse it.

But I really don’t understand what the problem is.

Suppose, I see sales figures for different car colors and form the hypothesis that from numbers of different-colored cars sold the largest group of cars on the street shoud be white. So I sit at some street one day and note all the colors of all the cars that pass me. Then I do some tests and find whatever.

Now, suppose I was bored and sat at some street one day and noted all the colors of all the cars that passed me. Since I love graphs, I plot a pretty histogram and find that white cars form the largest group. So I think that maybe most cars on the street are white and perform some tests.

How and why do the results or the interpretation of the results of the post-hoc test differ from those of the theory-driven* hypothesis test?

* What’s the name for the opposite of a post-hoc test, anyway?

I would like to add that most of our knowledge about the universe (the Earth moves around the Sun) is deduced post hoc from observation.

It seems to me that in physics it is perfectly okay to assume that it is not coincidence that the sun has been rising in the East for the last thousand years.