They are both correct but mean different things.
An article is a determiner, meaning it answers the question "which X" or allows you to pick out a specific X from many or a crowd of X's.
English strongly prefers all nouns have a determiner unless the noun is being used in a general sense or being used as a type or kind. In both these cases answering the question "which" isn't needed because we don't care about any specific X.
In conversation you often use nouns, and are talking about an instance of that noun previously mentioned in conversation, or previously observed by all parties in the conversation. So English provides the definite article the which signals that. If you don't know which X that the X is in a conversation you were not paying attention to something or joined the conversation too late.
According to the German legislation, school attendance is compulsory for children ages 6 through 16.
This means a specific instance of German legislation previously mentioned and believed to have been observed by all parties in the conversation by the speaker.
"Specific instance of legislation" probably means something like a specific single law, and "believed to have been observed by all parties" means something like that this has been on the news or the speaker/writer and listener had been talking about it.
The fact that "German" is mentioned here means that fact is important and implies we are possibly comparing legislation from other countries.
According to German legislation, school attendance is compulsory for children ages 6 through 16.
Here, there is no reference to a specific instance of legislation, and the speaker doesn't expect the listener to have any instance in mind. We don't care "which" German legislation, we are talking about all of it as a whole, or in general.