Mold is common with syrup. Especially syrup that is mixed thin. Less of a problem with thick syrup. Many folks add a few things to the syrup to prevent it. Things added are also, ideally, stimulants to the bees.
A standard, and safe, adder for many is bleach. 1 to 2 teaspoons per gallon of household bleach controls syrup mold, cleans containers, and extends storage. Up to a tablespoon per gallon is still safe but is much more than necessary. If you go that route, ensure it is actual bleach (sodium hypochlorite). There are ecofriendly-green bleach substitutes on the shelves nowadays. Even within well known name brands. Avoid those as they are different chemical make up. Read the labels to be sure of what is in the jug. You want traditional real bleach.
Other beekeeper brewed concoctions include blends of various essential oils. These can be found off the shelf in proprietary blends such as honey-b-healthy, pro-health, and others.
Do not add vinegars, acids, to the syrup. While acids help with mold with time and temperature those also convert sugars and in the process create toxic compounds in the syrup that will make your bees sick and may kill off your winter bees. The bees will also be turned off, feed much less, of vinegar laced syrup. The wasps and hornets will love it tho!
Keep it simple and to what the bees like. Bees do like chlorine. So use tap water to mix the syrup and add just enough of some real bleach to each batch to arrest mold.
Hope that helps!