Suppose a President has the opportunity to nominate a Supreme Court justice. The hypothetical President is a racist, sexist whatever and decides to make their nomination accordingly. In other words, the President will gladly pass up a qualified person who is not of the President's preferred race/sex/etc. to nominate someone who is. Is this legal?
There is no legal process whereby a demand can be made that POTUS nominate or consider a specific individual for some appointment such as a court position. There can be no law prescribing how such nominations come about, other than The Constitution which says that POTUS
shall nominate, and by and with the Advice and Consent of the Senate, shall appoint Ambassadors, other public Ministers and Consuls, Judges of the supreme Court, and all other Officers of the United States, whose Appointments are not herein otherwise provided for, and which shall be established by Law
Congress does not have the power to pass laws limiting how POTUS makes nominations, therefore whatever POTUS wants to do in this respect is a non-justiciable matter.