Have a read.
The funny thing about this passage is that Paul pits two quotations from the OT against one another. It's not made clear in the ESV, for some reason, but in verse 5 he quotes Leviticus 18:5. The Leviticus verse is clearly attributed to Moses, and is used by Paul to represent the sort of thing legalistic righteousness might say - basically, do and live (with the unspoken flip-side, fail and die). In verses 6 through 8, we have a mixed quotation from Deuteronomy - mostly from 30:11-14, with an introduction taken from Deut 9:4, and of course interspersed with Paul's commentary. The Deuteronomy quotation is not attributed, but is used by Paul to represent the righteousness that is by faith - basically, trust and live.
What is odd about this?
Firstly, Paul knows full well that the Deuteronomy quotation is from Moses; it forms part of the finale of his long farewell sermon on the plains of Moab. If he is really pitting Leviticus against Deuteronomy, this is a weird intra-Mosaic fight which would seem to be difficult within Paul's apparent doctrine of Scripture. (He has, of course, no recourse to the easy tools of modern critical scholarship; one suspects he would not have used them if he did).
Secondly, in context - and we should never assume that we can ignore the context of Paul's quotations and allusions - both passages say much the same thing. The whole point of the Deuteronomy passage is that Israel can and should keep the law - it is not a difficult of a distant thing. And given that the verses cited by Paul are immediately followed by 'see, I have set before you life and good, death and evil', it would be hard to insert the thinnest of knife blades between this and the Leviticus quote. On the other hand, the Leviticus passage itself, in the context of the book and of the whole Pentateuch, is hardly so legalistic as all that. The law is given only to a people who have already been rescued from Egypt, something which is surely significant, and as Leviticus is continually reminding its readers, Israel is to be holy because YHWH their God - the God who has graciously made himself theirs - is holy.
So what is Paul doing here?
My suggestion would be that he is not pitting two Scriptures against one another, but two hermeneutics. It is possible to read the OT and arrive at a legalistic conclusion. It is possible to conclude that God requires you to establish your own righteousness, and that he has provided the law as a means to do it. You can read it like that, and it will be broadly coherent. Paul argues in 9:32 and 10:3 that this is exactly what Israel has done in his day. This is their hermeneutic.
But it is equally possible to read the OT as teaching righteousness by faith. The Deuteronomy quotation represents that option. By interspersing the quotation with explicitly Christian emphases not present in the original text, Paul makes it clear why we should choose this hermeneutic over the other. The facts of Christ's death and resurrection in our place as the culmination of the story of the OT decide once and for all what it was that Israel's story was all about, and it certainly wasn't about establishing our own legal righteousness. We know the Old Testament was always about justification by faith because of Christ.