Syncgateway Error [4040] No such prepared statement

I haven’t seen that issue, but it sounds similar to the upgrade issue MB-38046 for 6.5 described here:
https://docs.couchbase.com/server/current/release-notes/relnotes.html#install-and-upgrade

Have you restarted Sync Gateway since the cluster was upgraded to 6.5?