Could I say these sentences this way?
Hanako was possessed by a ghost.
花子さんは幽霊に憑依されました。
A ghost possessed Hanako
幽霊は花子さんを憑依しました。
Could I say these sentences this way?
Hanako was possessed by a ghost.
花子さんは幽霊に憑依されました。
A ghost possessed Hanako
幽霊は花子さんを憑依しました。
憑依する is a correct word, but it is an intransitive verb that takes に. You have to say:
幽霊は花子さんに憑依しました。
The ghost possessed Hanako.
(or 幽霊が if "A ghost ...")
When you want to rephrase this with 花子 as the subject, yes, it's okay to say:
花子さんは幽霊に憑依されました。
Hanako was possessed by a ghost.
If you thought "Wait, passive voice of an intransitive verb!?", remember there is something called "sufferer passive" or "indirect passive" in Japanese (e.g., 妻に死なれた, 雨に降られた). Even an intransitive verb works like this (as long as Hanako is negatively affected by the possession).
取り付く is a wago version of this, and it's intransitive, too.
幽霊は花子さんに取り付きました。
The ghost possessed/haunted Hanako.花子さんは幽霊に取り付かれました。
Hanako was possessed/haunted by a ghost.
取り付く does not necessarily mean the ghost "gets in" and takes full control. As is the case with most kango-wago pairs, 憑依 sounds technical and specifically refers to the spirit possession, whereas 取り付く has other usages.