Handoff stopped working for messages
As a starting point, my suggestion would be to sign out of your account on the iMac, but not from the iCloud preference pane. Instead, sign out of Messages as follows:


Open the Messages app on your iMac
Go to Messages > Preferences...
Select the Accounts tab
Select your Apple ID/iCloud account
Click on the Sign Out button
At the next prompt, click on the blue Sign Out button
Once you're signed out, Quit Messages
Wait a couple of minutes repeat Steps 1 to 3
Go through the process of re-adding your account


Once you've done this you should get a notification on your iPhone saying that your account is now being used on an iMac. Once this happens, test to see if everything is working okay.