On this page of the Valheim game guide you will learn what the Swamp Key is used for.
In the Swamp you will find many closed crypts. Inside are valuables and numerous iron deposits. Entering these crypts is required to unlock iron. By default, these areas are not accessible and cannot be explored. This situation will only change once you obtain the Swamp Key. Only with it will you be able to get past the bars.
There's only one way to obtain the key - you must summon and kill The Elder. You will find the object on his body. Of course, you can get a few of these keys since the boss can be re-battled several times.