The Tower idea first saw daylight towards the end of 1066 as part of the Norman Conquest of England. William needed to cnstruct defenses for his new realm. The White Tower which gives the castle its name, was built by William the Conqueror and was a resented symbol of oppression, inflicted upon London by the new ruling elite; a bit like the Bastille in France. The castle was used as a prison from 1100 until 1952. But has also been a luxurious Royal Palace for centuries too.

It has served variously as an armoury, a treasury, a menagerie, the Royal Mint and is still the home of the Crown Jewels of England.
Royalty and nobles often has very comfortable lodgings just before execution. They arrived via the River Thames at Traitor's Gate. Some prisoners were in unpleasant lodgings and were tortured, such as Guy Fawkes. Most were executed nearby at Tower Hill. Rudolph Hess, Hitler's deputy, was held there for a while. The castle suffered bomb damage during WWII but was rapidly repaired and reopened as a key tourism attraction, as it has been for hundreds of years.

It must have been a wonder in the days when it housed the Royal Menagerie before zoos really existed, with lions and other exotic beasts and birds. These days there are only wire sculptured animals on display as remnants of a past exhibition. They are cleverly made from chicken wire.
There are still 7 ravens lving there and probably always will be as there's a saying that if the ravens leave the realm will fall.
For lots more info on the history of the Tower of London go to https://en.wikipedia.org/wiki/Tower_of_London