The law of conservation of mass is related to the first law of thermodynamics which states energy/matter cannot be created or destroyed.
A rusty nail weighs more compared to its original form due to corrosion (aka rust formation). Basically, water, for example from moisture in the air will react with the oxygen found in air and the metal ions on the nail's surface in a chemical process called oxidation. This process causes formation of iron oxide and iron hydroxide, which weren't present on the nail in its original form.
Therefore, in terms of the law of conservation of mass, the nail increased its mass by reacting with two surrounding sources, water and oxygen, (which both have mass) to form rust.
So, the weight added onto the nail by the rust didn't form out of thin air, but formed out of a chemical process which converted the water, oxygen, and metal of the nail into rust; thereby following the law of conservation of mass in that matter was formed out of pre-existing matter.