I am so confused about note durations in guitar. I know what note duration is. In guitar, if i play the low E string, it vibrates for a long time(sustain). I have no problem with the fretted notes because I can mute it by lifting my finger off. I see players that doesn't mute and it makes the solo sound rich but sometimes it is unwanted. If one note is played and the next is played, does the second note cancels out the first note?
The question is confusingly worded but it sounds like you're looking for solutions to damp unwanted, unfretted strings from vibrating after the intended note duration.
This is done by either left or right hand depending on the situation.
Left hand - just rest a finger on the string to damp it.
Right hand - rest a finger, or the palm of your hand to damp.
Basically you use anything that's not currently needed elsewhere to cover off strings you don't want to ring. Initially that may feel like a lot of juggling, but eventually it becomes second nature.
"If one note is played and the next is played, does the second note cancels out the first note?"
I think that this is at the heart of your question. I assume you know what a whole note, half note, etc are and how long they should last in terms of beats in a given time signature and tempo. However you seem to be confused about whether it is necessary to stop a note as soon as its required duration is over or if you can let it ring as you play other notes. This is a very interesting question and one that I think, if properly interpreted, could lead to many interesting answers.
A strict interpretation of the sheet music would indicate that once a note duration is finished you don't play it any more. On a woodwind or other instrument it might seem clear when a new note is played the last note is stopped.
What a guitarist does will depend on several factors.
First, the guitar is an instrument that decays fairly quickly compared to other instruments (depending on type and construction) and the notes are not driven like on a woodwind, brass, or bowed instrument like violin. As such, once a note is plucked its life is pretty short. This leads to the opposite problem to the one you just described. Namely, how can I keep the note going if it dies before its time is up. Guitarists will apply tremolo technique to simulate a driven note, like the violin. But that does not mean they should when playing whole notes in a baroque era piece. The technique is usually called out specifically for effect. So in many cases holding the note down will not really cause problems as it will die on its own anyway.
Second, the classical guitar (acoustic more generally) relies on resonance to improve the overall quality of sound and volume. When you play a G on the high e string the open G string should vibrate in sympathetic resonance, as will other strings that have G as a harmonic. This is a desired feature and one that classical guitar texts will urge the player to take advantage of. Along these lines many guitarists will finger notes in a chord that are not going to be played just to achieve this effect. In other words you want to use the left hand to finger notes not in the music but that are in sympathetic resonance to notes in the music to create a full rich tone. I only do this with chords and chord melodies where multiple notes are already indicated in the music. I would do it on a fast scale run for example as there isn't time to move quickly and perform additional gymnasts. Regardless one does not typically mute strings while playing scale runs (unless the sheet music calls for it) and the "ringing" adds a nice reverb effect.
Third, related to time are a few factors. One is the resonance and decay issue mentioned and the other is whether or not you can (1) lift the finger up to stop the note, or (2) dampen it with another finger without creating ugly buzzing sounds. Whether or not a player chooses to do this on their own depends on whether they feel it needs to be done, all things considered, and that they can actually do it without making a mess. Also, you may have no choice but to lift them as they will be needed sooner than later and you don't want them locked down.
Fourth, does the sheet music ask for a specific technique to be used. In some cases the composer may not want ringing and in other they may want more. In some cases there will be notes in the sheet music indicating what to do. Guitarists will often practice a piece several different ways to create multiple interpretations of the music.
Next, style is a factor. If the music is a fast staccato percussive piece then the more things resonate the worse it may sound. In contrast for a slow ballad the resonance can add effect. If there is a true dead spot in the music then the guitarists should in fact mute using one of the techniques mentioned in previous answers.
One final issue may be key or chord change where previous notes conflict with the new chord. In this case you really want to make sure the older notes are damped to avoid unintended harmonies.
You had motivated your question with "I see players that doesn't mute and it makes the solo sound rich but sometimes it is unwanted", well that is correct, sometime resonance is wanted and sometimes not. The real issue to me is are you seeing 2 different guitarists play the exact same piece differently or are you commenting on what you think is 2 conflicting ways to play the guitar? In reality both methods are valid and I'd expect a guitarist (acoustic) to master both methods. They can then choose to use them as an interpretive tool or execute them when the sheet music demands it. As for whether a stop to duration in the sheet music demands a stop in the note, that is a matter of taste as other strings will resonate anyway. A guiding principle for me is if the note that is ringing is in harmony with the next note in a chord melody sequence I don't worry about the ringing and leave it if it sounds good or if I don't need that finger right away. But if there would be conflicting harmonies or if I'm playing single note lines I do not attempt to let it ring.
I hope that addresses some of your thoughts.