It is not Shiva's own penis but the the penis of a hideous form which Shiva took to test his own devotees. Full story is in the Shiva Purana, Koṭirudra-Saṃhitā, Chapter 12 - The reason for Śiva’s assuming the phallic form (liṅga):
Śiva himself assuming a very hideous form came there in order to test their devotion. He was very brilliant but stark naked. He had smeared ashes all over his body as the sole ornament. Standing there and holding his penis he began to show all sorts of vicious tricks.
The wives of the sages were extremely frightened at this sight.
The sages, deluded by Śiva’s Māyā and plunged in grief, began to say—“Who is this? Who is this?” When the naked sage did not reply, the great sages told that terrible Puruṣa - “You are acting pervertedly. This violates the Vedic path. Hence let your penis fall on the ground.” When they said thus, the penis of that Avadhūta, who was Śiva of wonderful form, fell down instantly. That penis burnt everything in front; wherever it went it began to burn everything there. It went to Pātāla; it went to heaven; it went all over the earth; it never remained steady anywhere.
Brahma said:- "O brahmins, you though wise do such despicable things. Then why complain against the ignorant who act likewise? Who can wish for happiness after offending and antagonising Śiva thus? ...... As long as the penis does not become stationary there cannot be anything good in the three worlds...... Let the gods propitiate goddess Pārvatī and pray. If she can assume the form of the vaginal passage that penis will become steady. "
Lord Śiva said:— If my penis is supported in a vaginal passage there will be happiness. Except Pārvatī, no other woman can hold my penis. Held by her my penis will immediately become quiet.
After propitiating Pārvatī and the bull-bannered lord and performing the rites mentioned before, the excellent penis became static.
That phallus was held by her in that form then. When the phallus was stabilised, there was welfare throughout the worlds. O brahmins, that phallus became famous in the three worlds.
So it is the penis of a hideous form Shiva took in the ancient past.