WARNING!
If you attempt to do what follows, it will ERASE all your personal data completely.
So... you MUST have a known-good backup first. You have been warned!
My suggestion:
Use the "erase all content and settings" option (system settings) to "wipe" the internal SSD and reset it to "just out-of-the-box" condition.
(this also signs you out of iCloud and your Apple accounts)
Now you can either
a. sell it (once you do the above, it will boot to the original setup screen, just like new)
or...
b. restore your data for now and keep using it. You can always do the "erase all content..." trick again later on.
My GUESS is that the reason you can't log out is because there is some app or process going on in the background that won't quit, and because it won't quit the OS can't "log you out".
You could try looking in Activity Monitor to see if there are any open apps (that won't quit).
Or... try a logout that doesn't work, and then immediately open the Console and see what it says...