The Jedi Code isn't like you might be thinking it is. It's not a set of laws written in stone (although there is a mantra that they stick too). It is a Code that governs their life, forbids having more than one Padawan and also having romantic relationships. The Code teaches the Jedi to have compassion for all lives, and especially to not give in to anger. The mantra they use is:
There is no emotion, there is peace.
There is no ignorance, there is knowledge.
There is no passion, there is serenity.
There is no chaos, there is harmony.
There is no death, there is the Force
Anakin felt that spying on Palpatine was against what he thought of as the Jedi Code. Maybe he thought it created chaos where there should have been harmony. His interpretation of the Jedi Code was against spying on other people, especially if they happen to be one of your best friends. Even if they're actually a Sith lord in disguise.