Abu Amr Al-Awzaai said:

There is nothing more hated to Allah than for a scholar to visit a governor [1-2].


[1] Ihyaa ‘Uloom al-Deen 2/224.

قال الأوزاعي –رحمه الله-: ما من شيء أبغض إلى الله تعالى من عالم يزور عاملا

[2] Al-Mubarakfuri [May Allah have mercy on him] said in his commentary of Sunan al Tirmithi that: “the one who visits the ruler and adulates him has fallen into Fitnah, but the one who visits him and does not adulate him but rather advises him and enjoins him to do good and forbids him from doing evil then his visiting to the ruler becomes from the greatest Jihad.” [Edited from kalamullah.com]

 ومن دخل على السلطان وداهنه وقع في الفتنة وأما من لم يداهن ونصحه وأمره بالمعروف ونهاه عن المنكر فكان دخوله عليه أفضل الجهاد

Thus People of Knowledge have stated that a Scholar entering upon those in a position of authority ought to be for the purpose of advising  them to Goodness or for denouncing and forbidding Falsehood and Evil. As for those who enter for no reason or to gain fame and increase in status, then they have subjected themselves to a great Fitnah. For this reason, the visits of the People of Knowledge to the Rulers should be to advice them when they are in need of advice, for making goodness and evil clear to them, and for establishing the good of the public.