The Deities and Demigods book suggests that the nature of divinity is possibly gained from a number of different sources.
The Greek gods were born into it, being descended from Titans. This is called "Innate Divinity".
"Earned Divinity" is when a person does some great or unique deed and is granted divinity based on that right.
"Stolen Divinity" suggests murdering an existing God and stealing his power for your own.
"Imparted Divinity" is when a God gives a mortal a portion of their own power, giving them divine ranks at the cost of their own. Zeus does this for the newest of the Greek Gods.
There is also "Surrendered Divinity", when a God willingly gives up their divinity (temporarily or permanently), for whatever personal reason.
As the DM, you decide when or how to grant divinity. These are just easy suggestions.
In the D&D Cosmology, all of the Gods except Vecna (who earned it) and St. Cuthbert (who was imparted with it) were born into it.