If i remember correctly, it was the imps that put the codes that would eventually make Doc Scratch in the kids and trolls rooms, but was it ever explained why?
The imps didn’t do that. The trolls (or more specifically Team Scourge/Charge and Gamzee) wrote them themselves. And from what I can tell, they did it because they were compelled to by either Doc Scratch or Skaia itself