All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
First of all, you should know that there are no contradictions in the rulings that Allah has revealed; it is not at all permissible to describe them as such because Allah is the All-Wise and the All-Knower. Allah Says (what means): {Then do they not reflect upon the Quran? If it had been from [any] other than Allah, they would have found within it much contradiction.} [Quran 4:82]
If it appears to some of us that there is a contradiction, then this is due to our limited mind and understanding.
There is much wisdom in the Sharee’ah allowing the Muslim man to marry women of the People of the Book who are chaste; we may know some of this wisdom and we may be unaware of much of it.
Perhaps the most apparent wisdom is that the People of the Book have a heavenly religion and they agree with Muslims in many matters of religion. If they are in close contact with them and the Muslim has the upper hand and is the guardian, then he can correct so many mistakes and wrong concepts that they have about Islam and Muslims; in which case, this could be a reason for the non-Muslim women to become Muslims, as well as their relatives, especially if the husband is a religious man and has a good moral conduct.
Their embracing Islam is a great benefit and a noble objective. Al-Kasaani from the Hanafi School of jurisprudence, said in his book Badaa-i’ As-Sanaa’i’:
"The Sharee’ah permitted marrying a woman from the People of the Book hoping that she will become a Muslim, because she believes in the books of the prophets and messengers in general [..] The husband calls her to Islam and clarifies the truth to her; so the marriage of the Muslim to her is because of the hope that she will become Muslim. Therefore, it is permissible to marry her for this praiseworthy objective, contrarily to marrying a polytheistic woman." [End of quote]
The permissibility of marrying a woman from the People of the Book does not contradict what is stipulated regarding the prohibition of taking the People of the Book as close friends and allies.
The affection between him and her is a natural affection and not an affection for the religion; this affection is like loving the parents and so on. Allah, Glorified and Exalted be He, commanded that we keep good companionship with the parents after forbidding following them in their faith. Allah Says (what means): {But if they endeavor to make you associate with Me that of which you have no knowledge, do not obey them but accompany them in [this] world with appropriate kindness and follow the way of those who turn back to Me [in repentance]. Then to Me will be your return, and I will inform you about what you used to do.} [Quran 31:15]
What is meant is that the love of a Muslim man for his wife who is from the People of the Book is because of their marital relationship; but at the same time, he hates the disbelief that she is upon.
Therefore, coupling love and hatred, in this case, is possible, because each one of them has its own reason, so there is no contradiction.
An example of this is that you find that people hate the medicine because of its bitterness, but (at the same time) they love it because of the benefit of cure.
With regard to your saying: “Or is the prohibition of befriending Christians and Jews only confined to times of war?” the answer to this is that being allies to the non-Muslims is forbidden both at the time of war and at the time of peace. However, there is difference between taking them as allies and being fair with them and being righteous towards them. These are two different cases; if someone is at peace with the Muslims, the Sharee’ah advocated us to be kind to him, contrarily to the one who is at war with the Muslims.
Allah Says (what means): {Allah does not forbid you from those who do not fight you because of religion and do not expel you from your homes - from being righteous toward them and acting justly toward them. Indeed, Allah loves those who act justly. Allah only forbids you from those who fight you because of religion and expel you from your homes and aid in your expulsion - [forbids] that you make allies of them. And whoever makes allies of them, then it is those who are the wrongdoers.} [Quran 60:8-9]
For more benefit, please refer to Fatwa 1234.
Allah knows best.