How does a matched filter know about input signal beforehand?
A matched filter is used when the shape of the "desired" part of the received signal is known. Under the additive white Gaussian noise (AWGN) channel, a matched filter is the optimal detection scheme in the maximum-likelihood sense. This is a commonly-modeled case, so matched filtering is a typical signal-processing operation.

Based on your question, I think you're misunderstanding what a matched filter is: it doesn't require full knowledge of the exact transmitted signal. Instead, it helps to sift out the transmitted signal from the noise that is received with it, allowing the receiver to make more accurate decisions on what was actually transmitted.


Consider a baseband communication system that transmits a rectangular pulse with amplitude $1$ to communicate a zero and $-1$ to communicate a one. The appropriate matched filter in this case would be a rectangular pulse that matches the shape that is used by the receiver. 
When the train of transmitted rectangular pulses is passed through the receiver's rectangular matched filter, the result is a train of triangular pulses (the autocorrelation of a rectangular pulse is a triangle pulse). 
The receiver then makes symbol decisions based on the amplitudes of the triangular peaks that it observes. At this point, the SNR is maximized, as the matched filter tends to pass the signal of interest while averaging out any additive noise.


This is a simple, but representative example. The matched filter doesn't carry any of the transmitted information in itself (as you noted, that would be nonsensical); instead, it is used as an optimal means of extracting the transmitted information from the observed waveform.

I would also call your attention to this very good answer to a previous question about matched filters. It contains many of the diagrams that would make the above discussion easier to understand but I didn't have time to produce. It's a great resource for additional details.