The president warned of “serious consequences” if Mr. Musk chose to back candidates against Republicans who supported his domestic policy bill.