Many substances, especially those that are solids, have a certain porosity, that is, they have voids or cavities in their structure that allow water to enter. So when we weigh these substances we often do not get the true value of their weight, but we also weigh the water contained in their pores.
When we heat the substance, the water begins to evaporate and leave the body of the substance. This process does not happen immediately, sometimes it must be left for several hours under heating, so the sample is measured several times to make sure that the water has been completely released.
Performing this process reduces the number of errors since we have a more accurate measure of the mass, for example for a chemical reaction a certain amount of mass is needed for the reaction, if we weigh less amount because there is contained water the reaction may not occur as expected.