The simplest explanation is that the actual number is somewhere between 23,000 and 24,000. If an exact number was required in Numbers 25:9 then it is highly unlikely a head count would have come up with exactly 24,000 bodies. However, 24,000 is a very good round number. So is 23,000 as recorded in 1 Corinthians 10:8. Somewhere between 23 and 24 thousand souls died. The point is made – a huge number of Israelites died because of immorality arising from association with the pagan worshipers of Baal.
NIV Study Bible Notes: The Hebrew and Greek (Septuagint) texts of Numbers 25:9 have 24,000. It is clear that Paul is not striving for exactness. He is only speaking approximately. First century writers were not as concerned about being precise as 20th century authors often are.
ESV Study Bible Notes: Numbers 25:9 says 24,000 died. Both are fair approximations, rather than an exact number, of the people who died, which probably was all that either writer intended.
Another possibility is that the account in Numbers includes “all the head ones of the people.” Moses ordered the judges to carry out that command. So that account includes the head ones executed by the judges as well as all the others executed by God. Paul’s account may not have been as specific.
Source: https://wol.jw.org/en/wol/d/r1/lp-e/2004247#h=1:0-9:0