A US judge has criticised President Trump's lawsuit against the IRS for being improperly motivated and referred one of his lawyers for possible disciplinary action.