Did the Apostles Know they Were Writing Scripture?
There is a well known and (for evangelicals) well-loved section of 2 Peter (probably the verse most people are actually familiar with) in which Peter describes Paul’s writing as “scripture” (2 Peter 3:15-16). The problem is that this is very strange. At best, it is rare for NT writers to refer to other portions of the NT as Scripture (1 Tim. 5:18 is debated). This has led many to conclude that this section of 2 Peter is so blatantly anachronistic that it cannot be written by Peter.
We can’t deal with the entire issue here, but we can ask the most fundamental question: is it too early (under the assumption that Peter wrote 2 Peter at the end of his life) in Christian history for contemporary writings to be referred to as “scripture” in the technical sense? It certainly is early, but not too early.
First, the idea of a “canon” of Scripture is not foreign to Jesus and his contemporaries. This was disputed among a previous generation of scholars, but most have moved on to the consensus that the NT apostles and prophets inherit a canon-consciousness from their Jewish forebears, regularly referring to the Hebrew Bible as “the scriptures,” which is correlatively described as an “old covenant” (2 Cor. 3:14; Heb. 8:6).
That way of speaking—old and new—is important. Jesus himself contrasts the covenants in this way, referring to his own death and resurrection as establishing a “new” covenant (Mark 14:23-25) and placing his words above those of Moses (Matt. 5-7; cf. Heb. 3:1-6). (It should be said, though, that Jesus and the apostles do not believe that the “oldness” of the old is a strike against it; quite the opposite, since its antiquity establishes its authenticity; 2 Pet. 1:19). This covenantal contrast is fundamental to apostolic discourse (Gal. 3:19-29; Rom. 5:12-21; Heb. 7:12), and with it comes the somewhat obvious implication that the New Covenant, like the Old, is attended by new (God-spoken and Spirit-wrought) revelation (Acts 2; 1 Cor. 12:1-11; Heb. 1:1-2, 2:1-4; 1 Pet. 1:10-12).
While much of this revelation is verbal and “charismatic,” some of it originates within, or is preserved by, written discourse, just like it was “of old” (Luke 1:1-4; John 20:31; Heb. 2:1-4). Furthermore, as the apostolic age begins to close, we unsurprisingly find an increased emphasis on the “delivered” (that is, finished) quality of New Covenant revelation, and as such believers are called to pay close attention to what has already been received, rather than to expect further information in the near future (1 Cor. 11:23, 15:3; Eph. 2:20; 1 Tim. 1:15 (and the like); Jude 3, 17; Rev. 22:18-19), of which the entire book of 2 Peter is an example. In short, it is no leap of logic, even in the lifetime of the apostles, for early Christians to begin to refer to Christian writings as “scripture,” and this may not be the only such instance (1 Tim. 5:18)

So, the tldr: there is no good reason to think the predication of “scripture” upon Paul’s writing is anachronistic. Or, to more directly answer the question in the headline: the apostles knew that, in many instances, they were authorized vehicles of God’s divine New Covenant revelation, some of which would very likely become the foundation for the church age and thus constitute scripture.
As a side-note, though, it’s worth saying that almost everything about this classic painting is wrong.