A semivowel is a vowel that acts like a consonant (including only W and Y and yet U sounds like W sound in words such as penguin, sanguine, but not in guide. Can anyone tell me why?
You've got things backward in your question. Orthographic <u> doesn't ‘sound’ like anything at all: it's a letter, not a sound. Writing is an attempt (both syn- and diachronic) to represent the sounds and patterns of spoken language on paper. Different people speaking different languages have approached this task in different ways throughout the ages.
In Latin, for example, lowercase <u> and uppercase <V> were not distinguished: they both represent the vowel /u/ and the glide /w/, since the two represent one phoneme. Words like sanguine have been borrowed directly from mediaeval Latin (as used and spoken by the Old French, but different from the Old French vernacular) into English, along with an approximated pronunciation (which has since changed somewhat in English). The spelling is basically kept intact, though, rather than being transformed into *sangwine or something like that.
A word like guide is ultimately Latin in origin, but English borrowed it from the Old French vernacular, where some sound changes had already happened—for one, the /w/ glide had disappeared, though the spelling had not been changed. So here there never was a glide /w/ in the word (from the English perspective), but again the spelling in the language the word was borrowed from was maintained.
As Henry said, penguin is a Welsh word in origin, pen gwyn ‘white head’. This is a later word than the other two, and at the time, it was apparently felt that <gw> looked ‘un-English’ somehow due to the paucity of other words using this combination to represent /gw/. The only places where <gw> really appears in English is across morpheme boundaries, like in longwinded. So when the Welsh was borrowed into English, the spelling was not kept intact, but adapted to look more English. This often happens when the source language is not a ‘classical’ one (Greek or Latin and its descendants). Thus, the glide /w/ in penguin was represented with the more ‘normal-looking’ <gu>.
In other words, the presence of a <u> in a word like one of these can either just be a historical coincidence (maintaining a way of spelling something in a different language even though it has no clear connection to anything in the word as it is borrowed into English), or it can be an attempt to actually represent the glide /w/ in the word as it is pronounced in English. As always in English, you must know both how to pronounce and how to write the word—you can't guess one from the other.
penguin comes from a name for the Great Auk in the north Atlantic, and is thought to be Welsh pen + gwyn (head + white). Drake then switched it to the south Atlantic in 1578.
Both sanguine and guide come from French and do not have this difference there, though those with a classical education or who attended Latin mass would have known of the Latin sanguis or sanguineus where the u does involve a semi-vowel.