Mold grows in marijuana because the plant almost always contains some moisture content. There are practices that can be used to prevent mold in weed (such as by packing it with a dessicant, sealing it in nitrogen gas or by using ant-fouling agents) but more often than not there is some moisture content present which can lead to mold.
While some mold is inevitable even in dry weed (although in small amounts this is probably the same as is present in the air we breathe) when you can clearly see the mold on the weed it is to be avoided. At best it can leave you with a headache but in the worst case it could leave you with a systemic fungal infection which, depending on your other health issues, could be potentially dangerous. Smoking moldy weed on a regular basis could also result in mold balls growing in your lungs which are difficult to treat and may require surgery. Whilst these are worst case scenarios and a small amount of mold is probably safe, smoking moldy weed should be avoided.