Cleanrooms serve a very important role at NASA besides ensuring that the electronics and other sensitive equipment are protected during the production and testing process. Cleanrooms also keep microbes and very small organisms from stowing away on a trip to space.
Most of the time the extreme heat and cold that come with the launch will kill most things, as well as the vacuum of space. But there is still that “life” could be discovered outside of Earth on another planet, when in fact it may have been mistakenly transported from Earth.
National Geographic has written a great article detailing why cleanrooms are important in the hunt for life outside of Earth. You can read it here.