What difference would a "law" make?
The current constitutional settlement is that the Queen, in making an appointment, acts on the advice of her ministers, and her ministers advise her to appoint the person who leads a party or coalition that commands a majority of the House of Commons.
Suppose she didn't. Suppose she decided to appoint someone else. Then the "rightful" Prime Minister would lead the House, and if necessary the Army, and remove the appointed PM and probably remove the Queen as well.
Suppose there was a law, and the Queen broke the law and appointed someone else. Then the "rightful" Prime Minister would lead the House, and if necessary the Army, and remove the appointed PM and probably remove the Queen as well.
The "Law" or the "Constitution" can only define what should be done in normal situations. It can't define what the Queen can do unconstitutionally.
So forget all about the Queen acting politically in any way at all. All matters of the Queen's political power are done by her ministers. She has absolutely no say in who she wants to be Prime Minister.