See the section "Permanently remove a device from your account page at: Check your Apple ID device list to find where you're signed in - Apple Support
"If you're still signed in with your Apple ID on the device, it might reappear on your account page the next time your device connects to the Internet. To permanently remove the device from your account page, sign out of iCloud, iTunes & App Stores, iMessage, FaceTime, and Game Center on that device, or erase that device." --> How to factory reset your iPhone, iPad, or iPod touch - Apple Support
The first part of that paragraph tells you to do what you did by signing out so I am wondering why you say you couldn't sign out? Read this document Sign out of iCloud on your iPhone, iPad, iPod touch, Apple TV, or Mac - Apple Support