Currently both DatabaseItemTermStore and DatabasePropertyTermStore check whether they should perform write operation based on the "foreign id prefix" (check via DatabasePropertyTermStore::disallowForeignEntityIds).
In case (e.g. Wikimedia Commons) where items and/or properties are coming from the database of non-local entity sources those classes should not do any INSERTs or DELETEs either, despite the ID having no custom prefix.
For similar checks, WikiPageEntityStore has assertCanStoreEntity:
private function assertCanStoreEntity( EntityId $id ) {
if ( $this->dataAccessSettings->useEntitySourceBasedFederation() ) {
$this->assertEntityIdFromKnownSource( $id );
return;
}
$this->assertLocalEntityId( $id );
}