Solomon’s request for a “hearing heart” was not a request to magically become some kind of insightful sage, but for ears to hear the word of God, for a heart that absorbs its specific content, and acts accordingly.
God explicitly forbade His people in the Old Testament from marrying Canaanites because they worshiped false gods, a practice that Yahweh knew would lead Israel astray.