Spikenard has nothing in particular to do with Joseph. What is going on, is the following.
There is an apocryphal tradition to do with how Joseph and Mary were married. Variants of the story can be found in the Protoevangelium of James, Gospel of Pseudo-Matthew, Armenian Infancy Gospel, Book of the Nativity of Mary, and History of Joseph the Carpenter; and were repeated in later tradition, most notably the Legenda Aurea of Jacobus de Voragine. Basically, Joseph was chosen out of several candidates by a miraculous sign - a dove flew out of his staff, or possibly landed on his staff, or possibly there was no dove and the staff blossomed.
Lanzi and Lanzi claim a further tradition, where at the beginning of Mary's pregnancy, the devil mocked Joseph, saying that her virginal conception was no more likely than his staff blooming - which it then miraculously did.
The story is very like that of Aaron in Numbers 17, whose rod blossomed with almond flowers as a sign of the divine favour resting upon him. Indeed, some say that Joseph's rod was the very same one. Moreover, because of Aaron, the almond flower (Hebrew shakad) is associated with being a watchful guardian (Hebrew sheked, to be wakeful), which is also reasonable for Joseph. And so he is sometimes shown with almond flowers, specifically. The staff, of course, is a sign of power or authority, in both cases: it is also connected to the royal Davidic lineage.
Alternatively, and perhaps more commonly, the flowers are lilies. These are more naturally Mary's flowers, but it is fine to give them to Joseph as well: they represent purity, virginity, matrimony. Recall that Joseph did not consummate his marriage, nor is he believed to have committed adultery (see Molanus for the belief that Joseph's flowers can be said to signify his continence).
Now, in the cited Hispanic tradition, the flowers have become spikenard and the staff has vanished. If we look at a painting like The Heavenly and Earthly Trinities (c.1675-82, Bartolomé Esteban Murillo) we can appreciate why.
As to the flower, painters will tend to paint the flowers they know. A flower commonly called nard in Spain might not be the same nard as in Italy, or Israel. The general idea of something vaguely lily-ish or almond-like persists, but the "model" may end up being something botanically different. That said, the associations of spikenard - self-sacrifice, humility, faith - are also reasonable to attribute to Joseph, so the link can be justified, leading to its persistence.
For the staff, there has been a concern for a very long time about denial of the virginal conception of Christ. For example, the fourth-century Panarion of Epiphanius includes a lengthy defense of why Joseph had nothing at all to contribute in this regard (see Heresy 78). The artistic problem is that Joseph's staff - already suggesting a certain virility - with a spray of white flowers at one end, might bring to mind improper and heretical thoughts. In art, then, the size of the staff may be reduced, perhaps even to a simple frond or bough, as in the Murillo painting.
- Saints and their symbols. Fernando and Gioia Lanzi. Liturgical Press, 2004. (Trans. Matthew O'Connell from Come riconoscere i santi e i patroni nell'arte e nelle immagini popolari, Editoriale Jaca Book SpA, 2003).
- Bibliotheca Sanctorum. Pontifical Lateran University, 1965. Volume 6, pages 1251-1291, "Joseph".
- De picturis et imaginibus sacris. Jan Vermeulen ("Molanus"). 1570. Book 3, chapter 12, De picturis Ioseph.