What does rain 雨 have to do with mold 霉 and bad luck?
《說文・黑部》 

黴，中久雨青黑。从黑，微省聲。
「黴」 (Zhengzhang OC: /*mrɯl/), blackening from being afflicted by prolonged rain. From semantic 「黑」 (black) and reduced phonetic 「微」 (/*mɯl/).


The character 「霉」 (mould, mildew) did not exist originally, with the word that it represents being originally written as 「黴」. From character definitions, 「黴」 originally referred to the dark mould spots on garments from prolonged exposure to moisture, such as when rain hits and causes an environment to be damp. This is the direct correspondence between mould and rain.

The correspondence between 「霉」 and unlucky is less certain, with the word being written variously throughout history as also 「倒楣」 and 「倒煤」. You can find folk etymology explanations, but the choice of the second character for this word is most likely just a phonetic loan.

References:

《王力古漢語字典》
中國哲學書電子化計劃

宋・徐鉉等奉敕校定　漢・許慎《說文解字》