There are some further definitions of court. See Merriam Webster.
They're the same in both sentences. They're both referring to the official legislative court, definitions 1b and 1c from above.
Student or Learner
All of the following sentences are from Philosophy in an Hour by Paul Strathern.
He took an appointment at court of Archbishop of Mainz.
Still no summons came from the royal court.
To the surprise of no one, except Leibniz, the emperor chose to ignore this proposal – and also surprised Leibniz by ignoring his request for a high-ranking post in the imperial administration. By this stage Leibniz was in the employ of no less than five different courts.
In 1711 he met Peter the Great of Russia, who was so impressed by the philosopher that he appointed him a counselor to the Russian court.
Negotiations opened between London and Hanover, and George Ludwig decided to make use of his librarian’s political and genealogical expertise, which was so highly esteemed throughout the courts of Europe.
As far as I know there are two meanings of the word 'court'. The first is 'the place where legal trials take place and where crimes, etc. are judged' and the second is 'the official place where kings, queens and etc. live'. How can I differentiate between them in those sentences?
Those definitions seem more like a parliament, a council or an assembly to me. Also, you said "They're the same in both sentences." However, I gave five sentences.
Well, they may sound similar in that they're groups of people, but in a royal court the ruler either makes all the decisions or delegates authority. There's no democracy or voting as there would be in parliaments, councils, or assemblies.
In all five of your sentences, the term 'court' is used to refer to the concept of a royal court - a collective institution or administration, which governs the kingdom through direct or indirect influence of the ruler.
A royal court would have all sorts of designated positions, both high and low ranking. In additional to the important political positions, it was common to have official court positions for even minor duties, such as court jesters, court musicians, court composers, court artists, etc.
A court musician for example might play his instrument at an official court event, or simply just for the ruler's personal enjoyment.
Wear short sleeves! Support your right to bare arms!