The 40 year old opinion is more popular and comes from the narrator al-Waaqidi. There is very lengthy kalaam (debate) on whether al-Waaqidi is a reliable narrator or not.

This article below explains it and concludes that ALL the scholars have rejected him on the basis that he is weak in hadith transmission (i.e. pertaining to the laws of sharia and halal and haram) but some of the scholars (not all) have have accepted his narrations about the seerah of the Prophet pbuh and the battles of the Prophet pbuh:

https://www.letmeturnthetables.com/2012/01/muhammad-ibn-umar-waqidi-narrator.html?m=1

But Al-Waaqidi also has been criticised in his narrations of seerah and maghaazi as well. Namely that he would not care about the chains of narration of what he was reporting (by mentioned narrations with disconnected chains known as munqati) and also the fact that he would mix different reports together in the name of a single report.

But the scholars have generally been more lenient in accepting weak hadith about the seerah and maghaazi but not about halal and haram and the usul of the religion (aqeeda and fiqh.) So much so, that the same narrators who said he was weak have cited him for matters about the seerah and maghaazi. Such an al-Dhahabi.

The other opinion is that Khadija was 28 years old and comes from Ibn Ishaaq.

Ibn Ishaaq narrates: Abu Talib and Khadijah Bint Khuwaylid died in the same year and that was 3 years before the migration of the Prophet pbuh and Khadijah was buried in al-Hajun and the Prophet entered the grave when she was buried, and the day she was married to the Prophet pbuh she was 28 years of age. [Mustadrak Al-Hakim 4837/435, Darul Kutub Al 'Ilmiah volume 3 pg 200]

Ibn Ishaaq is a reliable narrator according to Islamqa. https://islamqa.info/amp/en/answers/148009

He has some problems, but the problems he has are more insignificant than that of the narrator Al-Waaqidi, who is rejected outright in hadith transmission. Namely that, Ibn Ishaaq used to do tadlees (drop narrators from the chain), used to write every single hadith down even narrations from people who were unheard of and said strange things, used to combine narrators but didn't differentiate their narrations and quoted them exactly the same as each other and more.

Despite this, Islamqa says he is not weak. But caution must be used when trusting his hadith.

Ibn Hajar al-Asqalani said about Ibn Ishaaq: The reports which are narrated by him alone, even if they do not reach the level of saheeh, they are of the level of hasan, if he clearly states that the narrator told him directly. End quote. Fath al-Baari (11/153) 

The opinion of Ibn Ishaaq that Khadija was 28 years old seems more likely because to deliver 6-8 children after the age of 40 is highly unlikely.

This is something interesting I stumbled across in another article about Khadija r.a and the biological clock for women:

  1. Khadijah's life history and her biological clock She died after been married to the Prophet pbuh for 25 years. When Khadijah rha married the Prophet pbuh, they were bestowed with 2 sons and 4 daughters. The names of the sons were Al-Qasim and Abdullah ( he was also called At Thoyyib and At-Thohir ) while the names of their daughters were Zainab, Ummu Kalthum, Fatimah and Ruqayyah. Zainab was the eldest daughter and she was born 10 years before the Prophet received his first revelation when he was at 30 years old. The second daughter was Ruqayyah and she was born when the Prophet pbuh was 33 years old. The third daughter was Ummu Kalthum and she was born when the Prophet was 34 years old. The last daughter was Fatimah and she was born when the Prophet pbuh was 35 years old. The two sons were born after the daughters. Thus if we look at the time the children were born, the age of the Prophet pbuh would be at least 37 years old. The last child born was 12 years after their marriage and Khadijah would be 52 years old if she was 40 years of age when she married the Prophet pbuh. Our scholars state that this is highly improbable as Khadijah would have reached the age of menopause which is normally experienced at the age of 45 years. If she was married at the age of 28 years, her last child would be born when she was 40 years old. The condition of woman during the time of the Prophet pbuh and the woman now is similar and the age of puberty as well as menopause is also the same.

http://ustazkamal3449.blogspot.com/2011/04/our-prophet-pbuh-married-khadijah-rha.html?m=1

Conclusion:

The opinion that Khadija was 28 years old at the time of marriage to the Prophet pbuh seems to be the stronger opinion on this matter.

The reason I quoted all these articles, was also to show you guys. That authenticating hadith is not easy. You have to be an expert to go back in the books and scrutinize each narrator to see if they were trustworthy or not and indeed it takes a very long time. It's easy to quote a bunch of articles to see the conclusions other people have come to. But when you have to go back to the hadith books yourself and the books of rijaal and so on it becomes an incredibly tedious task.

Which is more of a reason, we should be grateful to the scholars who have done the heavy lifting about our Deen for us. Otherwise we would be stuck.