Japanese Wikipedia doesn’t mention fertility or masculinity. It does say that they’re taken as being good omens and in China represent long life due to a belief that a rat which has lived 100 years becomes a bat.
The reason they’re thought to be good luck is because of the kanji used to spell the word: 蝙蝠 (koumori) The 蝠 is “fuku” meaning good fortune. The decision to use that character is most likely semi-random. They used to be called by a longer name in the Heian Period, 加波保利 (kahahouri.) Kahahouri at some point got shortened and the h’s turned to m’s. Once the popular pronunciation no longer matched the kanji, someone decided to use new characters that matched the new pronunciation and decided on 蝙蝠 for who knows what reason.
I did a quick google and apparently bats often appear with various things that represent fertility, so maybe the person who I heard it from got confused.
It’s not really semi-random, that’s the way it was written in Chinese during the Tang dynasty. The character 蝙 is formed of two part: 虫 (animal, insect) and 扁 (flat). Apparently, 蝠 meant “animal that clings onto things”. The character that means “good fortune” isn’t 蝠 but 福. As you can see, the two look very much alike, and in Chinese are pronounced the same way. This is most likely the origin of the belief. Such homophonic connections are very big in China, the most famous example being the number 4, which is unlucky because it sounds like 死 (death).
One theory as to the origin of kahahori is that it means ka-hofuri or “mosquito slaughterer”. The transition from 加波保利 (which is an old-style phonetic transcription) and 蝙蝠 didn’t happen quite as Sage Rat puts it. In the 1713 encyclopedia *Wakan Sansai Zue*, it is still listed as 加波保利, though a mention is made that it is now pronounced koumori. However, the use of 蝙蝠 is much older, as it occurs in the translation of Chinese texts. Think of it like having a technical latin name and a common english name. The katakana form of kahahori, カハホリ was used in Japanese zoological publications as late as 1919. It is in 1924 that koumori is adopted as the official technical term along with the 蝙蝠 characters, hundreds of years after the pronunciation had changed in speech.