Then why did God purposefully create a written source (the Bible) that portrays Himself as immoral ?
Could it be you/anyone are interpreting contrary to the intent of the source ?
Of course, this reply, and yours, is/was offered under the assumption that the Bible contains/is the word of God.
Once again, IF God IS, then whatever He does is righteous, the only issue is the interpretation/understanding of why, and theologians exist for that specific reason.