Matthew 23.27-28 actually uses the term γραμματευς, which means 'scribes'. However, the Gospel writers use γραμματευς interchangeably with νομικος, meaning 'lawyers'. Compare Matthew 23.13-39 using 'scribes' with the parallel Luke 11.42-52 using 'lawyers'.
More rarely this group is called νομοδιδασκαλος, which actually does mean 'teachers of the Law'. This word is used only a few times in the New Testament, only two having direct relevance: Luke 5.17 and Acts 5.34. (And a third time in 1 Timothy 1.7, though in a general sense.) This is actually quite a rare word in broader Greco-Roman literature. The Perseus Digital Library only shows two uses outside of the New Testament (1), but neither is helpful in identifying the social status of Jewish νομοδιδασκαλος during the first century.
Between 'scribes', 'lawyers', and 'teachers of the Law', we at least have a sense of what this people of this group intend to do: maintain and teach the Law.
The earliest definitive example of such a person in the bible, would be Ezra, 'a scribe skilled in the Law of Moses'. Ezra's role as a 'scribe' and teacher of 'the Law' is mentioned multiple times in Ezra 7, and Nehemiah 8 and 12. However, 'scribes' are mentioned in other cases in the Hebrew scriptures, but in the role of secretarial work for the courts. (2) Scribal work seems to have entailed a lot of record-keeping for the government, alongside Law-based duties.
The book Wisdom of Sirach was originally written sometime shortly before the Maccabean Revolt (167-164 BC), and contains a substantial description of just how important scribes had become between Ezra's time and the author's. Here, the author describes artisans, smiths, and potters, how cities cannot function without them...
Yet they are not sought out for the council of the people, nor do they
attain eminence in the public assembly. They do not sit in the judge's
seat, nor do they understand the decisions of the courts; they cannot
expound discipline or judgement, and they are not found among the
rulers. But they maintain the fabric of the world, and their concern
is for the exercise of their trade. How different the one who devotes
himself to the study of the law of the Most High! ... He will show the
wisdom of what he has learned, and will glory in the law of the Lord's
covenant. Many will praise his understanding; it will never be blotted
out. His memory will not disappear, and his name will live through all
generations. Nations will speak of his wisdom, and the congregation
will proclaim his praise. If he lives long, he will leave a name
greater than a thousand, and if he goes to rest, it is enough for him.
(Sirach 38.24-39.11, NRSVA)
Being a scribe was very reputable, and so the position carried great authority with it.
(1) Plutarch, Cato Major 20.4; Eusebius, Church History 1.8.1.
(2) e.g. 1 Chronicles 24.6; 27.32; Nehemiah 13.13; Esther 3.12; 8.9; Psalm 45.1. Jeremiah 36.32 mentions Baruch as a 'scribe', and Jeremiah 36.10 mentions 'Gemariah the son of Shaphan the scribe'.