The sensor is behind the mirror and the shutter, you can't see it unless you activate the cleaning mode which flips up the mirror and holds open the shutter.
When you are looking into the viewfinder, you are looking into some mirrors, then onto the main mirror, then out the lens. The light from the lens can't get to the sensor at this time because of the mirror (and the shutter). So anything that you see when looking into the viewfinder, is either on the viewfinder, the mirror, the lens or outside.
When you press the shutter release button, the mirror flips up and then the shutter opens so that the light can hit the sensor. The viewfinder goes dark while the mirror is up.
Because of this, anything that is on the viewfinder or mirror will not show up in the images. But dust that is on the sensor, can't be seen in the viewfinder but does show up in the images.