In se’if seven, AH notes Shulchan Aruch’s ruling that a man may not think about women while wearing tefillin, and if he is certain he will, better not to wear them. Rashi to Sukkah sounds like such thoughts do not prohibit the wearing, but AH thinks they are at least heseiach ha-da’at, losing sight of the fact one is wearing tefillin, which Shulchan Aruch linked to kalut rosh, inappropriate frivolity.
In se’if nine, AH brings that up in terms of weddings, if the festivities carry through until morning, where drunkenness and general frivolity might lead us to think the whole wedding party should not put on tefillin. Rema, however, considers the very fact of stopping the party for davenen also snaps people out of their wedding mode, sufficiently reminds them of the proper mindset of prayer to also allow wearing tefillin. Except that other authorities thought the group should be exempt because they are involved in a mitzvah, an idea Rema is willing to accept particularly in the summer (shorter nights), if the groom is still present.
