His most famous sonata were published in 1798, 1801 (Moonlight), and 1803. By then, he suffered from tinnitus and knew he was to loose his audition, but he could still hear. He gradually lost his audition during the 1810s and was deaf by the end of the decade.
TL;DR Beethoven wrote his masterpieces sonata at a time were he could certainly hear them.
Many of Beethoven's greatest works were composed when he was fully deaf (most famously his 9th Symphony, but also the Late Quartets, Grosse Fugue, etc.)
His greatest sonata “Hammerklavier” was written when he was almost completely deaf in 1818. I think this commenter’s insinuation that Beethoven’s best work happened while he could hear is largely false. Op 132, op 132, grosse fuge, 9th etc
TL;DR Beethoven wrote his masterpieces sonata at a time were he could certainly hear them.