That is a super back loaded contract. Year 5 he'll count 13.5m against the cap, despite his contract ending after 4 years.
But with the cap coming down, probably a lot, this year it makes sense. Cap hit this year will be a bit over 22m. Next year will be a 33m hit and they'll be praying that league revenues bounce back big time. The 40m hits in 23 and 24 will hurt, but will be prime candidates for a restructure, pushing even more money to those voidable years. Cowboys have thought ahead on that one - the contract is 6 years (last 2 voiding) even though the max proration period is 5 years, clearly expecting to want to convert salary to roster bonus in the future.
Honestly, I don't think this is a terrible deal for the cowboys. As long as Dak comes back from injury 100% and the league revenues recover next year this contract is probably a narrow win for the cowboys.