Hungary's president has signed a constitutional amendment ending his term, resolving a dispute with the new government.