Simply because their body mass is small. It's the same as if an ant falls off from the roof of a building. It will suffer no harm because the speed of its fall will be very slow, but try the same yourself and you will surely die.
More scientifically, it's a question of kinetic energy: $E_{kinetic}=\frac{1}{2}\times mv^2$
You can see from this formula that if mass is small, then kinetic energy will also be small.
The second reason is that although insects are small in size, the materials they are made of are extremely resistant comparatively to their size. Therefore, the bug will survive when it meets the window pane.
An interesting corollary is that the common saying "if an ant was the size of a human, it could carry a locomotive, because it can carry many times its weight" is totally wrong. If an ant the size of a man tried that, it would break its back just like you and me, because material resistance is not proportional to size.