The reason seems to be twisted running the queries in different threads. One solution is to launch your query as an interaction and preceed it with the pragma setting.
For example, replace:
d = self.dbpool.runQuery("DELETE FROM profiles WHERE name = ?", (name, ))
with:
def delete(txn):
txn.execute("PRAGMA foreign_keys = ON")
txn.execute("DELETE FROM profiles WHERE name = ?", (name,))
return None
d = self.dbpool.runInteraction(delete)