sed gives me ": unexpected EOF (pending }'s) error and I have no idea why

Try using newlines instead of a semicolons, at least before the branch commands (b) in the statements. See if this works:

sed -n "
  \${
    /^#/H
    x
    /${tapPrintTapOutputSedPattern}/p
  }
  /${tapPrintTapOutputSedPattern}/{
    x
    /${tapPrintTapOutputSedPattern}/p
    b
  }
  /^#/{
    H
    b
  }
  x
  /${tapPrintTapOutputSedPattern}/p
  /^Bail out!/q
" "$1"