Hola Karen
Yes, you could have said "ellos consiguen borrar los malos pensamientos de la cabeza" as we are clearly referring to bad thoughts in their own heads, not anybody else's head. Sometimes we do use the possessive to give a bit more emphasis, but both are correct. Maybe here, because we are already using the article in "los malos pensamientos", we then use the possessive for "su cabeza", so we don't repeat.
Saludos
Inma