Taking a hardhearted stance with 心を鬼にする
かわいそうだと思いながら、厳しい態度をとる。
To take a harsh attitude (with someone) while feeling sorry (for them).
Goo Dictionary
The expression 心を鬼にする means to take a stern attitude with someone for their sake, even though you feel sorry for them.
Note: This expression is only used when being strict with someone else, not when being strict with oneself.
Examples
好きな子がめがねを忘れた » Volume 2 » Page 119