I came across some words chatting with my friend (he's a native speaker). What's the difference between пиздато, охуенно, хуёво and пиздец? The first two words have a positive meaning but хуёво and пиздец are negative. Why? They derive from the same words, don't they?
This is similar to the following question about English: "Why does awesome mean great but awful mean something horrible?". The short answer is that the fact that a pair of words is derived from a common root does not mean that these words do not have opposite meaning. Moreover, the same word in different contexts can stand for completely different concepts.
For example, the word terrible in colloquial speech can be interpreted as "formidably great" - compare to ужасно круто / ты ужасно красива. Recall the English usage of fucking: it is used to indicate an extreme degree of something, either positive or negative.
As for why exactly some forms acquire positive connotation (охуенный, пиздатый) and some negative (хуёвый, пиздецовый), we can only explore when the connotation became common, but not why, I guess. Since you are asking about why and not about when, I consider this question answered.
To put it simply, this isn't something specific to Russian and "just because". :)
Just like in English you can add "fucking" to both "great" and "horrible", in Russian you can use the root хуй to express both positive and negative emotions. The body parts that хуй and пизда refer to are not "bad" or "good", they are just taboo to talk about — that's why, if you do refer to them, your speech becomes more expressive, more extreme; but not necessarily positive or negative.
As for the difference between these words, you got it right that пиздато is positive and хуёво is negative. Пиздец and охуенно, however, can also mean "extremely", or, in case with пиздец, "an extreme situation."
Он пиздец умный! ("He's so fucking clever")
Он охуенно тупой! ("He's so fucking dumb")
Это пиздец как круто! ("It's fucking awesome")
пиздато literally means something like 'cuntish', and is an expression of positive experience obtained by a heterosexual male's genitalia; you might hardly, if ever, hear heterosexual women saying 'пиздато';
хуево literally meas something like 'dicky', or 'prickish', and therefore is an expression of negative feeling of a heterosexual person equipped with male genitalia towards same sex genitalia; it might also have a slight overtone of self-denial;
охуенно is different; it is all about the o-prefix (cf. овладеть/овладевать, ополоуметь, одолеть/одолевать, ошеломить/ошеломлять, огрести/огребать, описать/описывать, остепениться, обрести/обретать, etc.), where the prefix has a meaning of 'taking smb/smth over completely, losing the sense of self-identity', and охуенно stands therefore for smth like 'having almost a sexual pleasure', 'feeling like turning oneself into a one big hard-on'
In addition to comprehensive answers provided above, I would like to add examples when nouns хуй and пизда (specifically in singular, nominative case) can be used to express negative meaning.
Хуй can be used to denote failure to obtain something or strong refusal:
Думаешь, они мне заплатили? А вот хуй! - You think they paid me? Fuck no!
Хотел пойти погулять. Хуй там! Пошёл такой дождь, что пришлось вернуться. - I wanted to go for a walk. Like fuck I could! It started raining so [hard], I had to go back.
Хочешь денег? Хуй тебе! You want some money [from me]? You get nothing, fuck you!
Пизда means something broke, or there are inevitable grim consequences ahead.
Моей машине пизда – двигатель сломался. My car is fucked up, its engine is broken.
Ну всё, урод, тебе пизда. Game over asshole, [I] will fuck you up.
Он разозлил начальника, теперь ему пизда. He made the boss angry, he's in deep shit now.
Also there are stable combinations like накрыться пиздой / пойти по пизде - this usually describes a technical device that started to malfunction so seriously it can't be fixed. At least, not without much trouble:
Телевизор накрылся пиздой / Телевизор пошёл по пизде.
All previous answers miss the point.
хуёвый mean different things because they are so similar to
Somebody took the adjective
отменный and made the taboo word
охуенный. Somebody else took the adjective
дерьмовый and made the taboo word
There is also word
опизденный which means the same as
Пиздец is made from
конец (тебе конец -> тебе пиздец). In one OS made in one of the Soviet computation centers in mid '80s, there were, among others, two commands: КОН, exit either from the current command/subsystem or from the whole system, and ПИЗ, immediate exit from all subsystems and from the system, no matter what.
Пиздатый is made from
поддатый (slightly drunk). Since it feels good to be in that state, the word
пиздатый means something good. Another word for becoming drunk is