I couldn't gather whether Rick & Co. came back on purpose, and lured the Termites in on purpose, or if they just happened back for some reason? They didn't seem to explain that. I like to think Rick did that on purpose, and basically used everyone in Gabriel's office as bait, more or less.
They came back on purpose. Leave in a big display, knowing they're being watched. Hide out while the hunters go into the church. Then go back.
The main reason it was confusing was because they filmed it to be confusing... they omitted the part about coming back from the planning scene so it'd be a surprise. You were led to believe that they were actually going to the school. Worked well in creating an amazing sense of tension, but not particularly honest.