You could, surely, if the physical size fits.
But that would be bad for the computer - as in, a G4 Mac will not work if you change its G4 type logic board to a G4 type logic board. They are different size, and there are dozens of differences between the items on them, their locations, wirings etc.
So if you want it to be actually a G4 to G5 upgrade that way, no, it will not work.
You may be better off selling your G4 and getting a newer Mac if some software etc you need requires that.