Gröbner bases of ideals invariant under endomorphisms