According to Catholicism, when is the Scripture source of infallible doctrine and when is it not? Infallible doctrines and dogmas of the Catholic Church are directly or indirectly based on Scripture. As this page states:


  The Church's Magisterium exercises the authority it holds from Christ to
  the fullest extent when it defines dogmas, that is, when it proposes truths
  contained in divine Revelation or having a necessary connection with them,
  in a form obliging the Christian people to an irrevocable adherence of
  faith.


Moreover, as this site states, these doctrines and dogmas must be explicitly taught by the Magisterium. 

Now, not every verse of the Bible that "seems" to define a moral or theological truth appears to be part of an infallible doctrine. Examples abound. I just present a few examples:


the Council of Jerusalem "defined" that Christians must avoid meet of strangled animals and to eat blood of animals (in Acts 15:20). Yet, this seems not to be an infallible doctrine of the Catholic Church. 
1 John 2:23 states that


  No one who denies the Son has the Father; whoever acknowledges the Son has the Father also.


which seems to suggest that non-Christians cannot "have" God [the Father]. Conversely, the Church does not deny the presence of God in non-Christians. This was stated clearly in Vatican Council II (e.g. see this page).


Meanwhile, plenty of other verses are directly used to define dogmas, e.g. about sacraments, the Church, sins, etc.

So, the relationship between moral and theological "truths" in Scripture and Dogma is such that all of dogmas emerge from Scripture, but not all of Scripture belongs to dogmas. 

The question is, then, why not all "apparent" doctrines of moral and faith in Scripture become dogmas?
A few things:


All true doctrines of Christianity are objectively dogma. 

Even if Arianism hadn't popped up, that Jesus was fully God would still be true. It would be a true Christian doctrine. Moreover, even if it was only implicitly believed (it wasn't only implicitly believed), that, too, would not mean it was not dogmatically true nonetheless. That it became a dogma centuries after Christ doesn't add to or take away from its truth, simply means that whereas before the Church had not needed to intervene and resolutely sided with and publically adopt to the exclusive of all others a certain theological doctrine, it now has, and the members of the Body of Christ must hear what the Spirit is saying. Thus the distinction between the true doctrine and the dogma is simply in the public status of the doctrine as, unequivocally, the doctrine of the only, holy, catholic and apostolic Church.
No doctrine of the Faith is 'based' on Scripture.

While Scripture in its own right, viewed purely in literary terms, or as a book (holy, true, and without error as it may be), is said to promote, condemn, etc. certain ideas and doctrines, whether it 'teaches' something is nonetheless, at the end of the day, subjective. (Just look at the many 'sola scriptura' religions that exist today, disagree, yet have the same authority in saying it is 'just what the Bible teaches.') Therefore, to cite Scripture as 'teaching' something is in every case to invoke or imply a pre-existing theology (i.e. which is true), relying upon whose truth one can show that the Scriptures must be interpreted in such and so a way, and not this other: whether or not it is admitted that a theology comes first, this is of logical necessity the case. As for the Catholic Church, She admits that theology comes first before reading the Bible, for many reasons, but chiefly because the Bible was not yet written in completion when “the faith once delivered to the saints” (James 1:3) was already deposited. Scripture doesn't generate Christian doctrine it informs our knowledge about them. No single Christian doctrine is purely based on a reading of the Bible, as though the Bible authors ever taught something only in one of their writings, or several of them.

So we can use terms like 'grounded' in Holy Scripture, or 'based' on it, but never in the sense that we learned a new doctrine by happening upon it in Scripture—only that it is as firmly Biblical as the Faith given along side it to the same Church. At the very least, we can never say that we learned a 'new' doctrine not already believed in its core essence at least outside of that Biblical revelation.

A historical example of interest (since you raised the point about sacraments) is something said in the Council of Trent in its decrees On the Sacrifice of the Mass:


  CANON II. If any one saith, that by those words, Do this for the commemoration of me (Luke xxii. 19), Christ did not institute the apostles priests; or, did not ordain that they, and other priests should offer His own body and blood; let him be anathema.


Now for a non-Catholic whose epistemology is sola scriptura, that seems like an attempt to read something wild into a few words (i.e. what they would consider 'the priesthood being based on the Bible.' But in Catholicism, we don't use a few words to 'prove' anything (i.e. in a way which would imply the belief can be known only by reading words in the Bible, and was not part of the faith once for all delivered to the saints at least implicitly). Supposing the Comma Johanneum is authentic, it wouldn't be what we 'based' the Trinity on (it wasn't, it was by pointing to the faith of the Christian Church before Arius popped up—“how many fathers can you cite for your [novelties]?”)1 On the other hand, it would be legitimate and lawful for the Church to declare, say, 'If anyone denies that by the words, 'the Father, the Word, and the Holy Ghost [are] one' the Apostle did not declare the Trinity to be the true and everlasting Godhead, ...' not because it is supposed to be saying that hereby the Trinity was 'undoutedly taught' but that the Church alone has authority to teach on her own Scriptures in this capacity, whence the Anathemas.

The Church isn't saying, 'See?' 'Do this in memory of me explicitly and uneqivocally teaches that Christ made them priests!' but rather 'See now, children, this is how I want you to understand my Book; I'll not have disobedient or fallen away children tell me what my own Book means or teach my children likewise.' That is, 'we the Church have the fullness of truth, the faith once delivered to the saints, a part of which is the priesthood, which pertains to the Last Supper, whence the meaning of the words 'Do this' of necessity refer to the priestly office of offering the Eucharist, not to some other heretical thing.'
The Council of Jerusalem defined doctrinal matters (the necessity of circumcision to "be saved")2 and also matters of discipline (which meats you can eat and how to eat them).3 The latter cannot be a matter of faith and morals, per the teaching of Jesus.4 It is rather a matter of discipline, dress, diet etc. 'Don't eat sausages on Wednesdays' doesn't carry the force of a moral doctrine on faith and morals, but it can still be a sin to disobey it, given which authority said it or asked it of you. Whereas 'Don't kill' has to do with the image of God and so forth, and is not something arbitrated, but something intrinsically moral (what goes into your pie hole has nothing to do with morality intrinsically)

Thus 'you need not be circumcized to be saved in the New Covenant' is different from 'we burden you with a commandment not to eat such and such in such and such a way' in an obvious way.
No one who DENIES the Son has the Father

For Catholicism, 'invincible ignorance' is when the truths of Christianity have not been presented to you, so leaving you excusable in that regard. It doesn't actually say what happens to their salvation5, only that such passages as ascribe damnable sin to those who deny Jesus explicitly or willfully by definition do not apply to someone. 'Not believing in the Son' because you favor sin instead is different from 'not believing in the Son' because you don't know who or what such is or means.6 Whence a definition of the statement and dogma 'outside of the Church there is no salvation' is given, namely, 'outside by their own volition' (just as an unqualified 'anyone who doesn't acknowledge me as God' obviously means 'knows me to be such, and does not reform their stubborn, wilfull ignorance and acknowledges me as such').




1 St. Athanasius, The Decrees of the Council of Nicaea.

2 Acts 15:1.

3 ibid. 15:20.

4 Matthew 15:11.

5 Cf. Pope Blessed Pius IX, Singulari Quidem, “... the Catholic Church ... is the temple of God, outside of which, except with the excuse of invincible ignorance, there is no hope of life or salvation.”

6 John 15:22.