The transition rotate function sets the rotation to 180deg both times it does not rotate it 180 degrees. If you want to rotate it back try with 0deg in the rotate back block or if you want it to turn all way round (and continue to always rotate clockwise) then you'll have to get the current rotation and add 180deg to that every time.
$(function () {
var flag_expand = 0;
$('#expand').on('click', function () {
if (flag_expand == 0) {
$('#expand').transition({
rotate: '180deg'
}, 1000, function () {
flag_expand = 1;
});
} else {
$('#expand').transition({
rotate: '0deg'
}, 1000, function () {
flag_expand = 0;
});
}
});
});