How can I log out of PSN on a friend's PS4?

Solution 1:

You can change your password for the PSN account for force a logout on all consoles. You can either do this via Password Reset (if you don't know the password) or going to PlayStation.com and changing your password by logging into your account (recommended option). Change your password from PlayStation.com > Account Settings > Security > Password.

If you Activated your Friend's PS4 as your Primary Console, you should deactivate the account from the console too. This is easier to do on the console, but if you have deleted your account, you can use the web to Deactivate All Consoles. You can do this from Account Settings > Device Management > Deactivate All Devices.