From the game's encyclopedia
Legitimacy is the representation of the right to reign of a Ruler. Vassals also generate Legitimacy Expectations that the Liege is supposed to meet.
Only Rulers have Legitimacy, which is calculated at the moment they become rulers and results in their Initial Legitimacy. A fraction of the Legitimacy of the previous ruler is also inherited by their Heir.
Legitimacy affects many of the game systems, making Marriage proposals, Vassalization and Alliances more likely to be accepted, and Claims cheaper, as well as swinging the Scales of Power in a Regency.
The game's text for patch 1.20.1.2. Words in blue are entries of the encyclopedia: hover one to read it, as in the game.
Legitimacy is an entry of Crusader Kings III's in-game encyclopedia. The game explains it: "Legitimacy is the representation of the right to reign of a Ruler." It covers Legitimacy Level, Expected Legitimacy, Initial Legitimacy and Mandate of Heaven. Patch 1.20.1.2, from game/common/game_concepts/06_ce1_game_concepts.txt and game/localization/english/game_concepts_l_english.yml.
Source: game/common/game_concepts/06_ce1_game_concepts.txt, game/localization/english/game_concepts_l_english.yml and the English localisation, Crusader Kings III 1.20.1.2.