Modern historians consider his ascendency to the Persian throne more or less a coup d’etat in which he killed off the legitimate heir to Cambyses and founded his own Dynastie: The Achaemenids. How did he legitimize his rule over the empire? How important was the Zoroastrian god aruamazda in the legitimization of his rule?
This is a very good question and one of the few regarding the Achaemenid Empire that we are fairly well-equipped to answer. The most important source for this is of course the famous Behistun inscription by the king himself (other sources, such as Herodotos, appear to be mostly based on the account given in the inscription).
[i.1] I am Darius, the great king, king of kings, the king of Persia, the king of countries, the son of Hystaspes, the grandson of Arsames, the Achaemenid.
[i.2] King Darius says: My father is Hystaspes; the father of Hystaspes was Arsames; the father of Arsames was Ariaramnes; the father of Ariaramnes was Teispes; the father of Teispes was Achaemenes.
[i.3] King Darius says: That is why we are called Achaemenids; from antiquity we have been noble; from antiquity has our dynasty been royal.
[i.4] King Darius says: Eight of my dynasty were kings before me; I am the ninth. Nine in succession we have been kings.
First, Dareios begins by asserting his descent from "Arsames, the Achaemenid". It isn't clear if Dareios expects the reader to be familiar with Arsames the Achaemenid (presumably a powerful Persian nobleman), but perhaps at least with the Achaemenids as an influential family. What he goes on to do after this declaration is remarkable - he traces his descent further back, to Teispes (Tishpa/Seshpesh), who we know from the Cyrus cylinder and some other sources was the great-grandfather of Cyrus the Great, and then asserts that the father of Teispes was Achaemenes, i.e., the eponymous (possibly legendary) ancestor of Dareios' family.
Another hint is given a bit further ahead in the text:
On the fourteenth day of the month Viyaxananote did he rebel. [Gaumata] lied to the people, saying: "I am Bardiya, the son of Cyrus, the brother of Cambyses." Then were all the people in revolt, and from Cambyses they went over unto him, both Persia and Media, and the other provinces. He seized the kingdom; on the ninth day of the month Garmapadanote he seized the kingdom.
The text reads as if Dareios expects any future reader to be familiar with Cyrus (but perhaps not necessarily Cambyses), and asserts that it was the claim of being the son of Cyrus that made possible this revolt of "Gaumata". From this we may infer that Cyrus was a famous and legendary figure already, much like Alexander would become soon after his death.
Dareios, interestingly, does not detail the family tree of Cyrus! It is left to the reader to infer that Dareios claims to be Cambyses' third cousin, and by extension, he suggests that Cyrus' claim to kingship derived from being a member of Dareios' own clan, the Achaemenids. Cyrus and Dareios were probably relatives, purely by virtue of being noblemen from the same general region, but probably not as close as Dareios asserts. Importantly, it is very unlikely that Cyrus was an Achaemenid - if he was patrilineally descended from Achaemenes, it would make no sense for him to stop his family tree at Teispes in his own records.
So Dareios leaves a suggestion as to a relationship with the legendary Cyrus, but does not dwell on it. This makes sense - after all, he is doing exactly what he accueses "Gaumata" of doing! The inscription is rhetorically astute enough to not read "Now I am a REAL relative of Cyrus, that's why I deserve to be king instead". So, how does Dareios shore up the claim that he is entitled to kingship purely by virtue of being an Achaemenid? Actually, this is pretty clear if we go on to read the inscription - Dareios goes on to list innumerable "rebellions" and "lies" that he had to put down, aided by other Persian nobles. In other words, Dareios' claim in itself was not necessarily all that credible to the nobility - he waged war until he had annihilated anyone who challenged it. As for how he won the support of the various Persian chieftains who supported him in his coup, this we do not have any real way of knowing. Perhaps they were most interested in maintaining Persian hegemony above all else, and Dareios was the most credible man to do so among them.
Having secured his massive realm, we know that Dareios went on to implement tributary reforms that made the royal house ridiculously wealthy, and mobilized enormous amounts of manpower to construct monuments, palaces, inscriptions, even a script for Old Persian. Commoners less well versed in the genealogies of Persian chieftains who were bombarded with Dareios' propaganda would have little reason to question it at this point, and positions previously held by defeated rebels would most likely be occupied by Dareios' staunch supporters.
As for the ceaseless references to Auramazda in Dareios' inscription, they seem to be at least in part drawing on Babylonian tradition of invoking the gods' approval of the Great King's virtues as one source of legitimacy. Dareios was by all appearances a master propagandist who was able to merge Near Eastern traditions of royalty with the norms of his own culture - but also, Auramazda would have been identified with gods such as Khumban, Zeus and perhaps Marduk, so it's not that much of a leap to make. His constant invocation of "the Lie" is a distinct element deriving from the norms of Zoroastrianism, though.
This is my favorite event in Persian history. Maybe all of history, so thank you for asking and giving me an excuse to talk about it. u/lcnielsen already gave you a solid answer addressing the dubious concept of an "Achaemenid" family linking Darius back to Cyrus and the religious details. I want to get into the political grit that surrounded the grandiose propaganda.
First of all I think the actual political situation surrounding the "legitimate heir" needs a bit more light. Now, like you point out in your question modern historians don't believe the story of an evil impostor taking Bardiya's place. There are varying degrees of how much scholars buy into different parts of the story. Some dismiss "Gaumata" as someone invented by Darius from nothing. Others take more of a compromise approach and suspect that Gaumata really was a magus who played a role in Bardiya seizing power. But most importantly, we can see in the Behistun inscription that Bardiya upset the balance of royal power while Cambyses was still living. The Behistun inscription describes it:
On the fourteenth day of the month Viyaxana (11 March 522 BC) did he rebel. [Gaumata] lied to the people, saying: "I am Bardiya, the son of Cyrus, the brother of Cambyses." Then were all the people in revolt, and from Cambyses they went over unto him, both Persia and Media, and the other provinces. He seized the kingdom ; on the ninth day of the month Garmapada (1 July 522 BC) he seized the kingdom. Afterwards, Cambyses died of natural causes.
So from the first time he "seized the kingdom," Bardiya's legitimacy was pretty shaky since Cambyses was still the legitimate king. Muhammad Dandamaev suggests that the Behistun Inscription gives two dates for Bardiya seizing power because he took control of governing the kingdom in March, but only had a coronation as king in July, possibly after Cambyses had died. Regardless, we enter into the whole affair with Bardiya as possibly a de facto usurper. When Cambyses died, Bardiya was the legitimate heir, but he'd taken power too early, which put him into doubt.
The other answer covers the role of the "Achaemenid" family in the post coup propaganda, but you also asked in another comment if Darius was just some random noble. Truly, there's not any proof one way or the other (assuming we ignore Darius' own claims) but I lean toward there being some relation. Darius does not claim any close relation to Cyrus and his family, he's only a third cousin in his own propaganda. If Darius really was inserting his family into Cyrus' family tree, then he didn't think he could claim to be very closely related and still get away with it.
Otanes, who first organized the conspiracy against Bardiya according to Herodotus, was also supposedly an Achaemenid. Both Darius and Otanes, as well as the other conspirators, seem to have been with Cambyses in Egypt. Darius was a spear-bearer - a member of the royal honor guard - to Cambyses. These Achaemenids seem to be a highly placed family, and in ancient monarchies highly placed families tend to be connected to the royals.
Over that many generations, it's highly doubtful that Darius was the only third cousin available. Plausibly, Otanes was related to the same degree, and both Darius' father, Hystaspes, and grandfather, Arsames, were both alive at the time, and thus closer to Teispes and Achaemenes, the ancestors claimed by Cyrus and Darius respectively. Ultimately, the family tree was not the sole key to his success. For reasons unknown, Darius was selected from all of the viable candidates as the new king. Maybe it was his relative youth. Maybe it was some kind of standing he had with the army or some personal connection with Cambyses or other nobles. Like I said, reasons unknown and probably a variety of factors.
After Bardiya/Gaumata was dead and Darius was on the throne there were six major steps toward true legitimacy. Three of them have already been covered by lcnielsen: claims of shared ancestry with Cyrus, claiming divine right from Ahuramazda, and extensive tribute and tax reform.
The first step Darius could have taken beyond those immaterial ideas was to marry into Cyrus' family. In fact, he did this multiple times. The Persian kings, like many ancient kings, practiced polygamy. Darius married two of Cyrus the Great's daughters: Atossa and Artystone. According to Herodotus, he also married Bardiya's daughter, Parmys. This was in addition to his existing wife, a daughter of his co-conspirator Gobryas. He had children with all three of the new wives and ensured a strong dynastic connection that reached directly back to Cyrus. As neither Cambyses nor Bardiya had any sons that we know of, this also made him the father of all legitimate heirs to Cyrus the Great irrespective of preceding events.
The next step, which dominates the Behistun Inscription, was to actually retake a huge chunk of the empire. Elam threatened to revolt, then Babylon actually revolted, and then provinces all over the empire went into rebellion.
King Darius says: While I was in Babylon, these provinces revolted from me: Persia, Elam, Media, Assyria, Egypt, Parthia, Margiana , Sattagydia, and Scythia.
That's the core of the empire in open revolt and Babylon went back into revolt again before the end. Darius had to orchestrate a multi-front war in the core provinces of the empire. Naturally he condemned all of the rebelling potentates as liars and impostors, but he still had to defeat them, and he did. Over the course of a little more than a year he reconquered the core provinces of the empire with military force. While not a traditional component of legal legitimacy, the right to rule by conquest was certainly on his side. Egyptian rebels apparently held out until as late as 518, and there doesn't seem to have been much action in Sattagydia (part modern Pakistan) until 515, but those were also returned to Persian control within a few years of Darius taking power.
Sattagydia is a good segway into the last step to imperial legitimacy. Up to this point, Persian imperial kingship had been tied to new conquests. Cyrus obviously established the empire, and Cambyses extended his reach to Egypt (the last foreign kingdom of note), northern Nubia, and the islands of the eastern Aegean. Thus, Darius's further foreign conquests were not only a way of enriching and expanding the kingdom, but also a way of proving his legitimacy. He, like his predecessors, was capable of great foreign conquests. When he went east to Sattagydia, he also conquered the rest of the Indus Valley to create the satrapy of India, and he also added the Sakā tigraxaudā, Sakā paradrayā, Thrace, and Libya, to his domain and Macedon was made a tributary.
So, in addition to religious claims and a dubious ancestral association with Cyrus and Cambyses, Darius also: established three dynastic marriages to graft himself more directly to the royal family, took the core provinces of the empire by force, and proved himself to be a efficacious conqueror in foreign territory.
In terms of realpolitik, I think those factors were probably more important than religious claims or the lineage he presented. That lineage was the basis for claiming a right to reconquer the empire, but he still had carryout those campaigns. In the Behistun Inscription, those victories are used as proof of divine favor, and realistically those wars are what secured his control. Then, by marrying into the family, he created an immediate and tangible tie to the throne that was apparent to all and could not be challenged. Finally, in conquering foreign lands, he obtained the same credentials as his more legitimate predecessors and proved that he had enough control at home that he could successfully go abroad without further uprisings breaking out.
Edit: Almost forgot! Major secondary references: