Can confirm, this works perfectly fine. Running GRX Di2 levers and an XTR Di2 RD with both 10-51 and 9-45 cassettes (chain line optimisation for fast/hillier races).
To run both cassettes, you’d need the SGS version (long cage). Not sure how smoothly the short-cage (GS) will work with the 51, if at all.
Another thing to consider is to run XD-driver type 12s cassettes (eg. Garbaruk). Much more choice on that driver. 12s Eagle and 12s Shimano is compatible.