Sometimes the "Join/Unjoin Roof" command works fine. Other times, I get the error, "Can't keep wall and roof joined."

I cannot figure out what it is that I am doing differently between the successful and unsuccessful roof-join attempts.

What steps do I need to take to avoid the "Can't keep wall and roof joined" error?