Theoretical description of a micromaser in the ultrastrong-coupling regime