Why did God create Satan, knowing what he’d do?
That same question could be applied to any sinner in this vale of tears. Why did God create me, knowing what I’d do?
God creates as an act of love. He gives us free will as an act of love because he desires our free choice to love him. Without free will there can be no freely-given love. Without the possibility of rejecting God, the gift of free will would be a sham.
God created the Archangel Lucifer, just as he created the other archangels and angels. Lucifer created Satan by his free choice to reject God. God allowed Lucifer to reject him because he gave the angels and he gives humans free will. But God also knew that as terrible as the evil wreaked by Satan was, God could still bring good from it:
The power of Satan is, nonetheless, not infinite. He is only a creature, powerful from the fact that he is pure spirit, but still a creature. He cannot prevent the building up of God’s reign. Although Satan may act in the world out of hatred for God and his kingdom in Christ Jesus, and although his action may cause grave injuries – of a spiritual nature and, indirectly, even of a physical nature – to each man and to society, the action is permitted by divine providence which with strength and gentleness guides human and cosmic history. It is a great mystery that providence should permit diabolical activity, but “we know that in everything God works for good with those who love him” (CCC 395).