They have a sizer at every gate for carryons and personal items, and if the gate agent thinks your bag looks too big they will ask you to put it in the sizer to confirm that it complies with the requirements. So it is random, but if you take your chances and lose, they will take away your bag and gate-check it.