The rule dates back to 1837.Clause five of rule 17 prohibits the wearing of hats in the chamber when the House is in sessionEvery member shall remain uncovered during the sessions of the House.
Comportment
5. When the Speaker is putting a question or addressing the House, a Member, Delegate, or Resident Commissioner may not walk out of or across the Hall. When a Member, Delegate, or Resident Commissioner is speaking, a Member, Delegate, or Resident Commissioner may not pass between the person speaking and the Chair. During the session of the House, a Member, Delegate, or Resident Commissioner may not wear a hat or remain by the Clerks desk during the call of the roll or the counting of ballots. A person on the floor of the House may not smoke or use a mobile electronic device that impairs decorum. The Sergeant-at-Arms is charged with the strict enforcement of this clause.
The only people breaking the dress code is the Congressional Black Caucus.
How masonic.