It is often observed subjectively in various instances, teachings of many Gurus may contradict Shastra. In such a case, what should be considered superior? What does Shastra itself say about this?
In a conflict between Guru and Shastra, what should be precedent?
The shastra takes precedence.
From the Manusmriti:
2.6 - The entire Veda is the root-source of Dharma; also the Conscientious Recollection of righteous persons versed in the Veda [Smritis], the Practice of Good (and learned) Men [Achara], and their self-satisfaction [ātmanastuṣṭi].
The order of precedence is given above in that verse, with shruti taking precedence over smriti, smriti taking precedence over achara, and achara taking precedence of ātmanastuṣṭi.
The teachings of the guru falls under "Achara".
The reason Shruti and Smriti take precedence, is because they are more reliable than one's guru's teachings, and also because the guru's duty is to teach the scriptures, so if he says to go murder, then that's wrong, because it conflicts with scriptural statements that say not to murder.
The meaning of Shastra;
Shastra (शास्त्र) is a Sanskrit word that means "precept, rules, manual, compendium, book or treatise" in a general sense. The word is generally used as a suffix in the Indian literature context, for technical or specialized knowledge in a defined area of practice.
Shastra has a similar meaning to English -logy, e.g. ecology, psychology, meaning scientific and basic knowledge on particular subject. Examples in terms of modern neologisms include bhautikashastra "physics", rasayanashastra "chemistry", jīvashāstra "biology", vastushastra "architectural science", shilpashastra "science of mechanical arts and sculpture", arthashastra "science of politics, economics" and nitishastra "compendium of ethics or right policy".
Any Shastra will evolve over a period of time, by the observation of many issues relating to one particular subject, as a result of discussions, etc. It may involve many experts of that particular subject. Let us call the experts of that field with reverence as Gurus. However, compilation of a Shastra may be done at a later date by a single Guru and that Shastra will go alongwith the name of that Guru only.
For example: The theories of Economics were in vogue in India for long. However, Chanakya codified in to Artha Sastra.
Similar is the case with any Shastra.
Now let us visit the question: what should be considered superior - Guru or Shastra, if teachings of Gurus contradict Shastra?
A genuine question indeed.
One person read an authoritative book on Vaidya shastra - Medical treatise. That person got some doubts in respect of a particular issue.
Here we have to consider 2 situations.
- the Professors of the college could not clear those doubts.
Here, the situation is that the book read was authoritative one, but no one nearby could clarify those doubts. In this case, it is better to stick to the book, though not understood completely, as Professors nearby cannot be relied upon.
- There is atleast one Professor, who could not only clarify doubts, but could teach an extensive part of the issue also.
In this case, the Professor or Guru is the Ultimate. Without hesitation, he should be followed, even if that Guru may say something differently than that was recorded in the authoritative book.
ईश्वरो गुरुरात्मेति - Iswara is Guru and Atman ( Dakshinamurthy Stotram - 7th Sloka)
Sri Krishna said in B.G.
तद्विद्धि प्रणिपातेन परिप्रश्नेन सेवया।
उपदेक्ष्यन्ति ते ज्ञानं ज्ञानिनस्तत्त्वदर्शिनः।।4.34।।
Know that through prostration, iniry and service. The wise ones who have realized the Truth will impart the Knowledge to you.
Shastra is a general term. If you mean sruti, then a true guru cannot contradict sruti. A true guru is living sruti. If you mean smriti, or any other meaning to scripture, than a guru can contradict, for two reasons. First, not being sruti, they are by definition written by man, not by God. Second, different sects accept different smritis as smriti. The real question is what is a 'true' guru. Swami Vivekananda writes (Complete Works, Volume 3, Bhakti Yoga, Qualifications of the Aspirant and Teacher, available here - https://advaitaashrama.org/cw/content.php):
In regard to the teacher, we must see that he knows the spirit of the scriptures. The whole world reads Bibles, Vedas, and Korans; but they are all only words, syntax, etymology, philology, the dry bones of religion. The teacher who deals too much in words and allows the mind to be carried away by the force of words loses the spirit. It is the knowledge of the spirit of the scriptures alone that constitutes the true religious teacher. The network of the words of the scriptures is like a huge forest in which the human mind often loses itself and finds no way out. — "The network of words is a big forest; it is the cause of a curious wandering of the mind." "The various methods of joining words, the various methods of speaking in beautiful language, the various methods of explaining the diction of the scriptures are only for the disputations and enjoyment of the learned, they do not conduce to the development of spiritual perception"
— Those who employ such methods to impart religion to others are only desirous to show off their learning, so that the world may praise them as great scholars. You will find that no one of the great teachers of the world ever went into these various explanations of the text; there is with them no attempt at "text-torturing", no eternal playing upon the meaning of words and their roots. Yet they nobly taught, while others who have nothing to teach have taken up a word sometimes and written a three-volume book on its origin, on the man who used it first, and on what that man was accustomed to eat, and how long he slept, and so on.
Bhagavân Ramakrishna used to tell a story of some men who went into a mango orchard and busied themselves in counting the leaves, the twigs, and the branches, examining their colour, comparing their size, and noting down everything most carefully, and then got up a learned discussion on each of these topics, which were undoubtedly highly interesting to them. But one of them, more sensible than the others, did not care for all these things. and instead thereof, began to eat the mango fruit. And was he not wise? So leave this counting of leaves and twigs and note-taking to others. This kind of work has its proper place, but not here in the spiritual domain. You never see a strong spiritual man among these "leaf counters". Religion, the highest aim, the highest glory of man, does not require so much labour. If you want to be a Bhakta, it is not at all necessary for you to know whether Krishna was born in Mathurâ or in Vraja, what he was doing, or just the exact date on which he pronounced the teachings of the Gitâ. You only require to feel the craving for the beautiful lessons of duty and love in the Gita. All the other particulars about it and its author are for the enjoyment of the learned. Let them have what they desire. Say "Shântih, Shântih" to their learned controversies, and let us "eat the mangoes".
The second condition necessary in the teacher is — sinlessness. The question is often asked, "Why should we look into the character and personality of a teacher? We have only to judge of what he says, and take that up." This is not right. If a man wants to teach me something of dynamics, or chemistry, or any other physical science, he may be anything he likes, because what the physical sciences require is merely an intellectual equipment; but in the spiritual sciences it is impossible from first to last that there can be any spiritual light in the soul that is impure. What religion can an impure man teach? The sine qua non of acquiring spiritual truth for one's self or for imparting it to others is the purity of heart and soul. A vision of God or a glimpse of the beyond never comes until the soul is pure. Hence with the teacher of religion we must see first what he is, and then what he says. He must be perfectly pure, and then alone comes the value of his words, because he is only then the true "transmitter". What can he transmit if he has not spiritual power in himself? There must be the worthy vibration of spirituality in the mind of the teacher, so that it may be sympathetically conveyed to the mind of the taught. The function of the teacher is indeed an affair of the transference of something, and not one of mere stimulation of the existing intellectual or other faculties in the taught. Something real and appreciable as an influence comes from the teacher and goes to the taught. Therefore the teacher must be pure.
The third condition is in regard to the motive. The teacher must not teach with any ulterior selfish motive — for money, name, or fame; his work must be simply out of love, out of pure love for mankind at large. The only medium through which spiritual force can be transmitted is love. Any selfish motive, such as the desire for gain or for name, will immediately destroy this conveying median. God is love, and only he who has known God as love can be a teacher of godliness and God to man.
When you see that in your teacher these conditions are all fulfilled, you are safe; if they are not, it is unsafe to allow yourself to be taught by him, for there is the great danger that, if he cannot convey goodness to your heart, he may convey wickedness. This danger must by all means be guarded against. — "He who is learned in the scriptures, sinless, unpolluted by lust, and is the greatest knower of the Brahman" is the real teacher.