The words "it only goes to show" usually introduce some pithy saying or some adage that is relevant to the facts at hand.
It only goes to show, you can't judge a book by its cover.
It only goes to show, fools rush in where angels fear to tread.
It only goes to show, a stitch in time saves nine.
When the pithy saying or the adage goes unspoken, it means the speaker believes he has no need to say anything more; he assumes the person he is speaking to will be thinking more or less what he himself is thinking. For example:
I always said that child would come to no good! His parents never disciplined him. They let him run wild. Now look where he is: in jail. It only goes to show...
The unstated adage might be something like "spare the rod, spoil the child".
Neither is incorrect, although it sounds far more idiomatic without "in", and that isn't a personal preference.
"Way", in this context, is often used interchangeably with 'style' or 'manner', both of which do require "in", for example:
- It was done in the style of...
- ...the manner in which it was done...
However, "way" literally means a route, or a direction, not strictly a style, and is more synonymous with 'method'.
Saying "in this way" can change the meaning - for example, if we said "walk this way", it would idiomatically mean in this direction; however, if we said "walk in this way", it would mean in this style, or manner.
Best Answer
It is worth noting that "learn the hard way" is often used in conjunction with explicitly stating an alternative way and conveys that the alternative had been easier but the person[s] involved chose not to take it and hence suffer more than needed. Another example:
Whether this statement is true or not, "learn the hard way" conveys that "being cautious" is easier than suffering the consequences of premature reopening. It would be totally different to use "learn by trial and error", since that would instead convey that they do not know and are not advised of a better way.