Ducati allocates its bikes based first on the team. Clearly the factory team gets the current year factory bikes. Pramac also gets current year factory bikes. It is in their contract with the factory. The other two teams, Gresini and VR46, have contracts that give them last years factory bikes. As mentioned, VR46 tried to upgrade their deal to get a current year factory bike, but failed. Ducati said they don't have the capacity to produce a fifth pair of bikes, they can only build four pairs of factory bikes a year. Each rider needs two bikes, so to give a rider a current year bike requires them to build two bikes and the spares required to run two bikes.
As mentioned, the four factory 2024 bikes (four pairs of bikes) will go to the factory team and the Pramac team. The contract Pramac has guarantees them two current factory bikes. This past years two factory team bikes and two Pramac bikes will go to the Gresini team and the VR46 team. As I understand it, they are specifically giving Marc Marquez Zarco's bikes from this past year. Zarco rode for Pramac, and as such was on a 2023 factory bike for that team. I do think it is interesting that they are specific as to which rider gets which set of bikes, with Zarco's set of bikes being given to Marc Marquez.
https://www.crash.net/motogp/news/1042742/1/ducati-confirm-marquez-will-ride-zarco-s-gp23-not-bagnaia-s-or-martin-s