Given a prepared transaction we remove it's txnid from the global table at the end of the call to __wt_txn_prepare. On __wt_txn_commit we call __wt_txn_release which does the same thing except in the case of prepared transactions.
if (!F_ISSET(txn, WT_TXN_PREPARE))
__txn_remove_from_global_table(session);
Now this wouldn't be an issue provided the prepared transaction wasn't being reallocated an id however when we commit the transaction calling __wt_txn_commit it calls __wt_txn_set_timestamp which calls __wt_txn_ts_log which if the flag WT_CONN_LOG_DEBUG is enabled calls __txn_logrec_init which calls ___wt_txn_id_check which then reallocates an id to our prepared txn. As such at the end of the call to __wt_txn_commit we don't clear our new id as our transaction is prepared which leaves an entry in the global table and blocks calls to rollback_to_stable when we're in debug mode.
To reproduce this failure add the following assert to __wt_txn_id_check:
WT_ASSERT(session, !F_ISSET(txn, WT_TXN_PREPARE));
And run:
./buildscripts/resmoke.py --suite=replica_sets jstests/replsets/transactions_wait_for_write_concern.js
In a debug build.