The question ‘is God an imaginary friend?’ has its intellectual roots in Hegel’s Idealism, which Feuerbach applied in a different way by supposing that people simply imagine God to exist (which is to say God exists as an idea only in the imagination). Freud developed this idea within the context of psychoanalysis and proposed the Projection Hypothesis, which says that people imagine God to exist because God satisfies certain desires, hopes, and fears in a way a father-figure can. My answer to the titular question was four-fold:
(1) Hegel’s Idealism can be realized by recent developments in digital physics. The deep logical structure to the Universe’s natural processes implies the existence of source code, which could be understood as God. If so, we would expect this source code (God) to manifest in everything, including us — which explains why we have consciousness and why we imagine and think about God.
(2) If cognitive arguments for the existence of God such as a Cosmological Argument can prove that God exists (or is at least implied to exist) outside of our imagination, then God is not an imaginary friend.
(3) The existence of God might be supposed for ethical reasons, in which case the relevant issue is living as though God exists, not imagining that God exists.
(4) The Projection Hypothesis can be flipped back on atheists who reject the existence of God because they have ‘daddy issues.’ Most atheists likely do not, which shows us that we should not mistake the motivation for a belief as the justification for that belief. And so if atheists can be rational in their disbelief, then theists can be rational in their belief too.