I'm not aware of any such time limit or window requirement related to maintenance programs that apply to the legality of sale transfers, and couldn't find anything myself, so I'll proceed based on the assumption the answer is "no" but would be very pleased if someone who knows can correct the record.
Airliners or aircraft in general are not required to be sold "mechanically fit" like a, car, as a condition of sale, or fit with the last x months or years. Regardless of who owns it or when it's transferred, it's airworthy and can be flown, or it's not, and can't (except for temporary permit to fly when you want to ferry an airplane from point A to point B, which you would do if you bought an un-airworthy but mechanically fit aircraft and wanted to get it to your own base).
So if an airliner is sold with a D coming up, there's nothing stopping the transfer from one owner to the other, even if it's at its D check interval limit and is grounded until the check is performed. The new owner can purchase it and apply for a ferry permit, or a short term extension to the D interval (there is usually some latitude allowed for special situations).
If I was buying an airliner that was only a thousand cycles short of a D, well that is maybe 6 months or 8 months of flying or whatever, and I might specify that the seller complete a D check as a condition of sale (as well as incorporation of all outstanding Service Bulletins), or, I allow for the risks in taking it with the unknowns of a major structural inspection coming up with this risk factored into the price (this can be evaluated by analysing how the airplanes of that type are holding up at D check across the fleet - some airplanes already have pretty onerous structural patching requirements by then, imposed by surprise results during fatigue testing).