The verse in Corinthians is part Paul's brief synopsis of the problems during the exodus from Egypt which he states are examples for the church:
6 Now these things took place as examples for us, that we might not desire evil as they did. 7 Do not be idolaters as some of them were; as it is written, “The people sat down to eat and drink and rose up to play.” 8 We must not indulge in sexual immorality as some of them did, and twenty-three thousand fell in a single day. 9 We must not put Christ to the test, as some of them did and were destroyed by serpents, 10 nor grumble, as some of them did and were destroyed by the Destroyer. 11 Now these things happened to them as an example, but they were written down for our instruction... (1 Corinthians 10:6-11 ESV)
Verse 8 is referring to the worship of the gods of Moab and the sexual immorality between the daughters of Moab and some of the Israelite men. This took place in Shittim (Numbers 25) and is known as the rebellion of Baal of Peor at which 24,000 died.
The discrepancy is between the 23,000 Paul states and the 24,000 written in Numbers. As noted elsewhere Per 1 Cor 10:8, when did God kill 23,000 for sexual immorality?, Paul’s 23,000 is sort of correct since the 24,000 who died would include 23,000; he is imprecise not wrong.
It is also possible to see that since Paul is using the events as examples, he was being precise.
First, the description of the 24,000:
Nevertheless, those who died by the plague (מַגֵּפָה) were twenty-four thousand. (Numbers 25:9)
מַגֵּפָה can also be translated as slaughter [H4045 - maggephah] as seen here:
The messenger replied, “Israel has fled before the Philistines, and there has also been a great slaughter (מַגֵּפָה) among the troops; your two sons also, Hophni and Phinehas, are dead, and the ark of God has been captured.” (1 Samuel 4:17 NRSV)
Since this event involved war מַגֵּפָה is taken to mean slaughter since "plague" would be associated with sickness or disease not armed conflict.
In the event of Baal of Peor, there is more than one means by which people died:
4 And the Lord said to Moses, “Take all the chiefs of the people and hang them in the sun before the Lord, that the fierce anger of the Lord may turn away from Israel.” 5 And Moses said to the judges of Israel, “Each of you kill those of his men who have yoked themselves to Baal of Peor.” (Numbers 25:4-5 ESV)
7 When Phinehas the son of Eleazar, son of Aaron the priest, saw it, he rose and left the congregation and took a spear in his hand 8 and went after the man of Israel into the chamber and pierced both of them, the man of Israel and the woman through her belly. Thus the plague on the people of Israel was stopped. (Numbers 25:7-8 ESV)
The “plague” was stopped after the leaders were hung and Phinehas killed the man and the Midianite woman. Some of the 24,000 died at the hands of men as in the war with the Philistines. Some translations reflect these facts:
but twenty-four thousand Israelites had already died. (Numbers 25:8 CEV)
The total who were "slaughtered" was 24,000, the leaders by hanging, 2 by the spear, and the rest by another means.
In the context of Paul writing to the church, the leader is Jesus, who like the Israelite leaders died while hanging. The example at Baal of Peor for the "church" is all of the others who died by some other means.
Consider that Paul does not actually say 23,000 died. He says 23,000 fell:
We must not indulge in sexual immorality as some of them did, and twenty-three thousand fell (πίπτω) in a single day. (10:8)
πίπτω means to fall down. [G4098 - pipto] It does not mean die, except in the sense that someone who dies normally falls down. However, Jesus died and did not fall because he was hanging at the time of death: exactly as the leaders who sinned at Baal of Peor died.
Paul draws attention to certain events because he claims they are "examples written down for our instruction." The example for the Church is the "everyone else" at Baal of Peor.
Paul's statement that 23,000 fell should be taken as a deliberate understatement of the total. He understands the significance of the leaders being hung in the sun. So in the letter to the Corinthians his understated amount is the better example for the people.