Spirits occupy the bodies of the dead
or
Spirits create forms to inhabit

Once it was decided that ghosts were not animated by the souls of the departed, the accepted notion was that spirits must then be the motivating force behind ghostly apparitions. Some believed that such (evil) spirits could simply animate a dead carcass.  The erudite James I held such a belief, for which he was satirized in Ben Jonson's The Devil is an Ass.

PHILOMATHES. And will God then permit these wicked spirits to trouble the reste of a dead bodie, before the resurrection thereof? Or if he will so, I thinke it should be of the reprobate onely.
EPISTEMN. What more is the reste troubled of a dead bodie, when the Deuill carryes it out of the Graue to serue his turne for a space, nor when the Witches takes it vp and joyntes it, or when as Swine wortes vppe the graues? The rest of them that the Scripture speakes of, is not meaned by a locall remaining continuallie in on place, but by their resting from their trauelles and miseries of this worlde, while their latter conjunction againe with the soule at that time to receaue full glorie in both. And the Deuill may vse as well the ministerie of the bodies of the faithful in these cases, as of the vn-faithfull, there is no inconvenient; for his haunting with their bodies after they are deade, can no-waies defyle them: In respect of the soules absence.   --James the First, Daemonologie, 1597, III,i, p.59.

A more popular theory was that the devil could create whatever form he chose in which to make an appearance.  Ludwig Lavater accepts this theory as a matter of course.

That it is no hard thing for the Deuill to appeare in diuers shapes, and to bring to passe straunge things.

But it is no difficult matter for the deuil to appeare in diuers shapes, not only of those which are aliue, but also of deade menne, yea, and (which is a lesse matter) in the fourme of beastes and birdes. &c. as to appeare in the likeness of a blacke Dog, a horsse, an Owle, and also to bring incredible things to passe, it is a thing most manifest for he may through long and great experience, vnderstande the effectes & force of naturall things, as of herbes, stones, &c. and by meanes heereof woorke maruellous matters. --Lavater, II,xvii, p.167.