Some Protestants have told me the term "ungodly" in Romans 4:5 refers to moral failing in a general sense, and from here they argue that Paul's point is that Abraham was a rotten sinner when he was declared righteous in God's sight. I don't deny that 'generic ungodliness' is a possible meaning for this term, so the Protestant side isn't helped nor is the Catholic side harmed if this is granted. But I think an even stronger case can be made that "ungodly" in Romans 4:5 refers to being outside the Mosaic Covenant, a much narrower meaning. Here is the article where I show the context itself leads the fair and honest exegete to see "ungodly" best refers to the specific parameter of being outside the Mosaic Covenant. In this article, I want to look at the word itself, especially the way it's used elsewhere in the Bible.
The Greek adjective in Romans 4:5 is asebes and is found in 8 verses: Rom 4:5; 5:6; 1 Tim 1:9; 1 Pet 4:18; 2 Pet 2:5; 2 Pet 3:7; Jud 1:4; Jud 1:15. The noun appears in 6 verses: Rom 1:18; 11:26; 2 Tim 2:16; Titus 2:12; Jude 1:15; 1:18. I don't deny nor have I ever denied that the predominant usage here refers to something along the lines of 'generic ungodliness'. With that said, it is interesting to note that in various verses the term "ungodly" is mentioned along with other terms pertaining to sinful living, suggesting there is a distinction between "ungodly" and moral failing in a generic sense. For example, even though 1 Timothy 1:9 uses the term "ungodly" it also mentions "lawless," "disobedient," and even "sinner," in the same breath. This suggests some distinction. And 1 Peter 4:18 also mentions "ungodly" and "sinner" in the same breath, which again would suggest some distinction. Jude 1:15b speaks of "ungodly sinners," connecting two terms, most likely referring to generic ungodliness, but still suggesting a distinction. Romans 1:18 distinguishes between "ungodliness" and "unrighteousness," which is quite interesting given how these terms relate to justification in the later chapters. So whatever this distinction is, it is clear that asebes does not automatically entail a 'generic ungodliness'.
The Old Testament is harder to deal with because even though the term "ungodly" appears numerous times, almost always referring to sinful living, in the Mosaic dispensation this could especially refer to not living according to the Mosaic standards of law and worship. So while "ungodly" in Genesis 18:23 is long before Moses and circumcision (and thus likely 'generic ungodliness'), a text like Psalm 1:1-2, 4-6 is certainly about David having in mind the Mosaic Law as God's ideal standard. And related to this is Romans 11:26, which speaks of banishing "ungodliness" from Jacob, which is most likely referring to violating the Mosaic Law, especially given the context of Romans 11 is about the Jews versus Gentiles.
There is one more piece of evidence to consult, and that is the fact asebes is the negated form of the Greek word sebo, which basically means "religious" or "devout." This is worth exploring because in understanding the positive meaning of sebo can help give a better understanding of what the 'negated' meaning (asebes) refers to. This word is found in 10 verses in the New Testament, and in nearly every case it refers to the the specific worship of God according to Mosaic standards: Acts 13:43, 13:50, 16:14, 17:4, 17:17, 18:7, 18:13. Two men stand out as being "devout" in reference to the Mosaic standards, in fact being called 'very devout' (the Greek word eusebius, from which the Church Father Eusebius is named), namely Corneilus in Acts 10:2 and Ananias in Acts 22:12. This certainly does not refer to generic devotion to God, but rather it is very concerned with the fact the Jews did make a positive impact on their Gentile neighbors, bringing them knowledge of the true God and the Torah. So to 'negate' this notion would result in the notion of someone 'not devout according to Mosaic standards', and thus in a genuine way supporting the 'outside the Mosaic Law' thesis.
From this brief look at the term itself, I would say the situation is by no means a simple open-and-shut in favor of what certain Protestants jump to conclude. The best case I could see them make is how Romans 5:6-8 seems to parallel "ungodly" to "sinner" (in an apparently generic sense), and then say this is in proximity to Romans 4. Regardless, as I said earlier, it ultimately proves nothing against the Catholic position, for the more important Protestant claim that God declares someone righteous whom He knows is unrighteous is flatly unbiblical.