Hämeenlinna is located at the line between Tampere and Helsinki which btw Finland's oldest train line. At least hourly, connections are offered in every direction. If you need to buy a ticket, be aware about the opening times of the counters which vary per weekday. At my last visit, the ticket vending machines had their menu only in Finnish and Swedish. Check the Finnish Railways (VR) page for actual schedules and fares.
Hämeenlinna's train station is located slightly off the town centre (around 800 metres), on the other side of the Vanajavesi lake. Coming from the train station, just follow Hämeentie (or Possentie and the coastline for a slightly longer but more scenic walk) to get to the bridge at Viipurintie. This bridge leads straight into the old town.
There is a boat line that can take you through the lake from Hämeenlinna to Tampere, but the catch is that it will cost you much more then the train, but it is something special :)
Check the link for more details.
If you need to get anywhere in the city, Hämeenlinna is rather small and taxi ride will be short and quick and so wouldn't cost too much either.
The easiest way to get to Hämeenlinna is by car or the train which take about one hour drive or ride from Helsinki or Tampere.