In the eddic poem Hrafnagaldur Óðins, stanza 6, Idunn is identified as an "elf" (alfar) and the "youngest of the elder children of Ivaldi." This implies that Ivaldi had two sets of children, probably by different mothers. Thus Idunn is a sister of the famous smiths, the Sons of Ivaldi. In addition to that, according to the Poetic Edda, Tyr is said to the sons of the giants(Jötunn) Hymir and Hroðr. In that case, how and why are these two gods?
To answer briefly: Being a god was not about belonging to a specific "race".
For Idunn, we can compare with the division of the gods into aesir and vanir, where the latter were in some sense linked to the alfar (in the poetic Edda, the term "aesir and alfar" refers to all the gods). Being linked to the alfar thus was not a disqualification.
For Tyr, having a giant as one of your parents was very common among the gods: Odin's mother was certainly a giant, and so was likely Thor's. Thor had one son, Magni, with a giantess (Magni is one of the gods that will survive Ragnarök and wield his father's hammer). Such pairings of gods with giantesses are extremely common: Frey and Njord both married giantesses. There is also Aegir, a giant, and lord of the Sea, possibly also the grandfather of the god Heimdall. Finally, there is Loki, who was explicitly a giant as well as a god.
Thus, being related to giants or elves was not in any way unique or something that diminished the status of a god. Being a god was about supporting the world order, not a matter of parentage.
The poem Hrafnagaldur Óðins is a very late addition to the Norse canon, probably written in the 1600s, which puts it a long time after paganism gave way to Christianity. This might explain the many oddities in its mythology. (For more on the poem and its context, you could download this pdf from the Viking Society.)
In the main body of lore (the Prose and Poetic Eddas) Tyr is said to be either the son of Odin or of a giant. The confusion about his origins may be because he seems to have been a Danish god, so an Icelander like Snorri Sturlusion, who wrote the Prose Edda, might have had to invent an origin for a god he didn't know much about.
(For more on Tyr as a Danish god you could look here:
Brink, Stefan 2007: “How Uniform was the Old Norse Religion?” in Learning and Understanding in the Old Norse World, eds. J. Quinn, K. Heslop, T. Wills, Brepols: 105-36. (Brepols; paywall))
Tyr & Thor were both sons of Odin, but each were raised by foster giant parents. Tyr's foster parents were the giants (jotuns) Hymir & Hroðr (sometimes named Griseldis) and Thor's foster parents were Vingnir & Hlor. In Thor's case he was sent to Vingnir by Odin because he was too much to handle for Frigga. Thor is sometimes know as Vingthor (an ekename).
Tyr was raised by Hymir as a sort of peace treaty with the giants. Kindof like after the Aesir & Vanir war gods were swapped between the two groups to create peace - Njord, Frey & Freyr came to live with the Aesir & Mirmir & Hoenir went to live with the Vanir. Funny thing is when Tyr & Thor were adults & went back to live with the Aesir, Tyr led Thor to Hymir & Thor ending up killing Hymir.
The Norse Myths by Heilan Yvette Grimes 2010 Hollow Earth Publishing