Assignment has higher precedence than comma , hence the result you get in the first case. You can find the entire operator precedence table here .
Why parenthesis makes comma operator to take last value and without parenthesis it takes first value?
Because parenthesis is used to override the precedence. The first case is implicitly equivalent to :
(i = 1),2,3,4,5;
Comma evaluates from left to right and the rightmost value is the value of the entire expression. Read the documentation here.
The comma operator has left-to-right associativity. Two expressions separated by a comma are evaluated left to right. The left operand is always evaluated, and all side effects are completed before the right operand is evaluated.