It does make a difference. The plural "heads" is the only correct version in this instance because the they subject is assumed to be plural. However, in some cases, a subject of "they" might be used as it is the preferred pronoun for a non-binary student, and then the singular "head" would be the correct choice.
Assuming a preferred they pronoun isn't the case, you could still reword the sentence to allow the singular "head":
A student learns so much in school but the moment they graduate, all the stuff they learned goes right out of their head.
In this instance, the singular student is used, and therefore the later they/their is also singular because the gender of the student is unspecified. If the subject were gendered (i.e. "A girl learns") then they/their would need to be replaced with she/her or he/his.