Putting class ranking in CV, but against dept guidelines I graduated last year from a master's course where I was fortunate enough to graduate top of my class. However I was told this in confidence by one of my referees to a PhD programme, and they informed me that under no circumstances was I to put this on academic applications, as it would be against 'department guidelines'.

I also tried to enquire with the department directly concerning class rankings, but as expected they were unwilling to reveal this information to me.

I'm now considering applying for a job, and believe that the class ranking would be a good thing for my CV. However I really ought not to know this fact, as it was revealed to me in confidence by my referee, and I risk jeopardising my relationship with him if the department found out. 

Am I overthinking this, and should I just put it down, or is there a way to resolve this in a less risky way?
So, you put it on your CV, the future employer does what employers do and phones the institution to check details of awards, years etc.

BOOM - the institution does not confirm you were "top of the class" as that is just not done.

Now the future employer is confused - what else may be wrong on your CV AND your referee is pissed at you as well.

Do you really want to go there?