As you study Swedish, you will notice that the definite form, or in more literal but less accurate terms the “the”-form, is often shown in two positions: at the beginning of the noun phrase and tacked-on at the end of the main noun in the noun phrase. In other words, you will often see the following constructions:
den svarta katten – the black cat
det röda biblioteket – the red library
In the first example, den starts the noun phrase and tells us that it is definite, i.e. that the listener or reader whom we are trying to reach should know which cat we are referring to. The same function shows itself in the form of a suffix to the noun katt as -en. The word katt receives den and -en as definite markers because it is of common or n-gender. In the second example, instead of den and -en we have det and -et. This is, of course, because bibliotek is a noun of neuter or t-gender.
(Technically, the definiteness of the phrase is also expressed as the suffix -a at the end of the adjectives svart and röd. As a side note, all adjectives within definite noun phrases receive the suffix -a regardless of the gender and number of the noun they describe.)
So, the question a lot of people have is this: Why express definiteness in two places?
The truth is, you usually only do this if there is an adjective in the noun phrase. If you just want to say “the cat” or “the library”, you leave out the first definite article (den or det) completely:
katten – the cat
biblioteket – the library
Note the “usually” in the statement above. There are cases in which one can say den katten and det biblioteket without any adjective in between. This is namely used as a short form for den där katten or det där biblioteket (that cat, that library, respectively).
There are also cases in which one can say den katt and det bibliotek. This is only allowed if there is a relative clause attributed to the noun provided. For example:
den katt [som sprang förbi precis] – the cat [that ran by just now]
det bibliotek [där jag hittade boken] – the library [where I found the book]
This construction is mainly used to emphasize that it really is a specific katt or bibliotek the speaker or writer is referring to, but it is also perfectly grammatical to say katten and biblioteket in this case as well (without den or det):
katten [som sprang förbi precis] – the cat [that ran by just now]
biblioteket [där jag hittade boken] – the library [where I found the book]
The difference here is the same as the difference between katten and den katten: adding den emphasizes the specificness of the noun in question.
But I still haven’t answered the question: Why is definiteness so complicated in Swedish?
Earlier forms of Swedish were much more complex in general. Swedish had basically the same complex grammar as modern Icelandic once upon a time. Simplification of languages over time doesn’t always occur to the same extent in all domains. The complexity of definiteness in Swedish is actually much simpler than it was a thousand years ago, but still not all grammatical differences have been wiped out. That’s why we have the system we have today.