TL;DR
Ayah 5:5 allows marriage and concubinage to the People of the Book. And you are allowed to love them and have close bonds with them.
Ayah 5:51 is more contextual and forbids taking People of the Book as protectors but this does not forbid one from being friendly or on good terms with them. The Arabic word, awliyā, in this ayah means protectors, not "friends" or "allies".
O you who believe! Take not Jews and Christians as protectors.
They are the protectors of one another. And whosoever takes them as
protectors, surely he is of them. Truly God guides not wrongdoing
people.
— Quran 5:51 in the Study Quran p. 698
In-Depth Explanation of Quran 5:51
This verse addressed to Muslims (O you who believe) forbids them to
take Jews and Christians as protectors (awliyāʾ). Awliyāʾ (sing. walī) can also
mean “friends” or “allies” (see also 3:28c; 4:139c), but here more likely denotes
those whom one would turn to as a protector or dominant authority. This term
and the verbal noun from the same root, walāyah, are used in the Quran to
denote the bonds of loyalty, mutual protection, and friendship that ideally mark
the relationship between members of the same religious community (see, e.g.,
8:72; 9:71). Although this is the only verse in the Quran in which believers are
urged not to take Jews and Christians, specifically, as protectors, believers are
elsewhere urged to avoid taking as protectors those who disbelieve (3:28; 4:89,
139, 144), those who mock their religion (v. 57), God’s enemies (60:1), and even
close relatives who prefer disbelief to belief (9:23). That Jews and Christians are
protectors of one another indicates that they realize those bonds of loyalty
among themselves, as separate religious communities; and in vv. 80–81, they are
criticized for having themselves taken “disbelievers” as protectors.
This verse reportedly concerned certain Madinan Muslims who had political
allies and protectors among the Jews. One report tells of the Companion
ʿUbādah ibn al-Ṣāmit, one of the natives of Madinah who had become Muslim
(Anṣār) but had maintained alliances of mutual protection with the Jewish clans.
He came to the Prophet to renounce his attachment to them and to declare that
his only “protectors” were God, the Prophet, and the believers (see v. 55).
Another Madinan Muslim, ʿAbd Allāh ibn Ubayy, subsequently came to the
Prophet declaring his need to maintain a similar relationship of protection with
his Jewish allies, and this verse then came down, instructing him and believers
generally not to do so (Q, R, Ṭ). Another account reports that after the Muslims
suffered the military loss at Uḥud, some Muslims, feeling vulnerable, established
allies among the Jewish clans. This verse was meant to forbid this practice (Ṭ).
The verse warns that whoever takes the Jews and Christians as protectors is
of them, meaning one of them. Thus to seek an alliance of mutual protection with
Jews or Christians is to identify oneself as one of them, since the relationship of
mutual protection (walāyah) with one’s coreligionists is what defines one, in
part, as a member of the religious community. See also 3:28 and 4:139, where
taking such allies apart from the believers—that is, apart from fellow Muslims
—is explicitly criticized. For some this means that the status of one who allies
with members of another religious community, such as with Jews or Christians,
has the same status, legally and theologically, as the other members of that
religious community (Q, Ṭū). The verse’s prohibition against alliances of
protection with those outside the Muslim community likely had much to do with
the fluid and somewhat precarious social and political situation of the fledgling
Islamic community during the time of the Prophet; and it is important to note
that Islamic Law, developed after the Islamic state had become fully established,
allowed agreements of mutual protection with non-Muslim states and political
entities. According to some commentators, this verse also means, in part, that the
relationships of inheritance between those who ally themselves with another
group and the members of the Muslim community are nullified, since the root
for awliyāʾ/walī can relate to inheritance as well as to mutual protection (Q, Ṭs).
The word for protector (awliyāʾ/walī) can also mean “friend,” and thus the
verse may cast doubt on the acceptability of Muslims maintaining amiable
relations with Jews and Christians, leading some but not all to conclude that one
should not have close relationships with them or confide in them (Z). Some
commentators include a report that the second Caliph, ʿUmar ibn al-Khaṭṭāb,
adduced this verse in an (unsuccessful) attempt to persuade his provincial
governor, Abū Mūsā al-Ashʿarī, to stop employing the services of his Christian
scribe (IK, R, Z). Nonetheless, most commentators as well as the reported
occasion of revelation for this verse make clear that here the word connotes
something closer to “protector” or “ally” and situates it in a context of the
Islamic community struggling to define and establish itself against those who
were enemies of the religion. The verse should not be interpreted as forbidding
friendly relations with Jews and Christians on a purely personal level, since such
a reading would contradict v. 5, which allowed for the most intimate of personal
relationships—marriage—to exist between Muslim men and Jewish and
Christian women, and 60:7–8, which states that Muslims may behave justly and
kindly to any who do not fight them on account of religion or otherwise oppress
them.
Source: The Study Quran p. 698-700