What is the justification behind requiring that people must reach a certain age before getting elected? Doesn't this discriminate against young citizens?
In the US there is no "justification". The two ages were put in place in two completely different eras for completely unrelated purposes.
The Latin root for Senate, Senex, means "old man". The initial idea behind the US Senate was that it was supposed to be populated by the two wisest men in each state (preferably picked by state leaders, not a popular vote).
From Federalist 62:
The qualifications proposed for senators, as distinguished from those of representatives, consist in a more advanced age and a longer period of citizenship. . . . The propriety of these distinctions, is explained by the nature of the senatorial trust; which, requiring greater extent of information and stability of character, requires, at the same time, that the senator should have reached a period of life most likely to supply these advantages.
So that's where the minimum of 30 years came from. The framers did not feel like anyone younger was liable to have acquired the level of wisdom the office requires.
The current US voting age was set by a Constitutional Amendment in 1971. There was an ongoing draft for the Vietnam war at that time. The general argument for that age was that it is the same as the draft age. It was felt that those old enough to be forced to fight for the country deserve the right to have a say in electing the leaders making those decisions.
Justifications will vary from place to place. You mention the US example in your question, and this answer presents the justification that the US founders gave for this part of the US Constitution.
Regarding the age-30 requirement for US Senators, Federalist 62 says:
The propriety of these distinctions is explained by the nature of the senatorial trust, which, requiring greater extent of information and stability of character, requires at the same time that the senator should have reached a period of life most likely to supply these advantages
This is discussed again in Federalist 64, along with the age-35 requirement for President:
By excluding men under thirty-five from the first office, and those under thirty from the second, it confines the electors to men of whom the people have had time to form a judgment, and with respect to whom they will not be liable to be deceived by those brilliant appearances of genius and patriotism, which, like transient meteors, sometimes mislead as well as dazzle.
Yes, by definition, this discriminates against younger people, but as these requirements are listed in the Constitution, that discrimination is constitutional discrimination.