Intention apparently plays a small part of it. A flagrant is broken down into two categories - a flagrant 1 is contact that is considered unnecessary and a flagrant 2 is contact that is considered excessive.
I assume since McDermott wasn't even trying to do anything contact related that this is where intent plays a part. If Hayward was attempting a lay-up and McDermott slapped at the ball and smashed him in the face or was swinging his arm recklessly, then it likely would been called a flagrant 1. I agree that it could have been called - as the contact was obviously 'unnecessary' - but here he looked to just be putting his arm up to play defense; he wasn't making an active play on Hayward. More just bad luck for Hayward, but at least this one won't keep him on the sidelines.