This temptation to think highly of one's self was something Paul himself had to keep in check all of his life, it was a left over residual from the great pride and arrogance of his pre-conversion life as well as a temptation due to the great privileges he had received from God in his ministry.
The grace given to me links with verse 6 – gifts that differ according to the grace given to us.
Everything in this passage is in the context of proving what the will of God is.
This passage is an extended explanation of how the mind is renewed and transformed in contrast to conformity. It explains how to offer your body as a sacrifice in an act of worship. These are the greater concepts to be kept in view while looking through these various instructions. Otherwise they can easily become yet another list of do's and don'ts of performance religion which is precisely what Paul is trying to steer us away from.
The world's way (and typical religion) to keep order and bring people together is through conformity – squeezing everyone into a similar mold. For obvious illustrations of this just look at a marching army, one of the typical symbols of worldly power. Each soldier is required to dress alike, cut their hair alike, move their body exactly the same in synchronization with every other soldier in lockstep. It presents a very impressive image of harmony and a sense of powerful identity. But it is very different than the analogy that God uses for His people.
God's idea of unity is that of a healthy body made up of all different limbs and organs and parts but working together in perfect sympathy and service to all the other parts. Each part of the body is valued and served and each part values and serves the rest of the body.
In the world's system every soldier looks like every other soldier – if you've seen one you've seen them all. But in God's body each individual is a unique part of the whole while different from every other part. They are not cookie-cutter clones multiplied many times to produce a sense of power but they are individuals gifted with a small portion God's immense grace, entrusted with unique gifts different from all the others but each one empowered with a measure of God's faith.
The primary bond and motivations found in an earthly army is fear and intimidation and pride. The motivation for healthy members of a body is love and selfless service for the rest of the body. This is all in the context of being shown mercy by God. Each member of the body has been classified as part of the group of disobedient ones so that God can equally show His mercy to all of them. Those who accept and embrace this mercy are enabled to become a functional part of the body of Christ. They have a tempered view of themselves in the light of God's mercy and are aware of the measure of faith given to them in His mercy. They are entrusted with unique gifts by His mercy and participate in loving, humble service to the rest of the body which unites them in joy bonds with each other.
Think so as to have sound judgment
The Greek here means to be moderate. This is in contrast to thinking arrogantly about one's self. Feeling that we are better than others is to forget that we all have been shut up in disobedience so that He may show mercy to all. When we keep in constant view our true condition before God then we will not so readily compare ourselves with each other. This is very important to keep in mind when observing the differences in our gifts.
The way the world sometimes deals with the problem of differences is to force everyone into a single mold like soldiers. This imposes external conformity but does nothing to deal with the pride or shame inside the heart. God's way to address the temptation of comparison and criticism is to remind us that we are all equally fallen in sin and in need of undeserved mercy. Our differing gifts are according to His grace, not according to our achievements or independence. This is very easy to say but very difficult to incorporate into our thinking. That is why Paul has to insert the warning to not think of ourselves more highly than we ought to think.
So where do we find the definition of what we ought to think about ourselves? In the surrounding context:
we were all disobedient,
we have all been shown mercy,
we each must give ourselves up as a sacrifice of worship to God,
we all need our minds renewed and transformed,
we all have received our measure of faith from God,
we all have received our differing gifts from outside ourselves to be used to serve others in the body.
All of our focus need to be on God instead of on our supposed naturally inherent or cultivated value.
It is God who has the riches of wisdom and knowledge,
it is God who is the past, the present and the future of all life,
it is God's perfect design of creation against which we have been disobedient,
it is God who has shown all of us mercy,
it is God who alone deserves our worship,
it is God who is the source of any faith that we possess,
it is God alone who can hold together the disparate parts of His body in perfect bonds of unity, love and joy,
it is God we should think more highly of than ourselves,
it is God who alone is worthy of all praise and worship.