Each function equation must have the same number of arguments. This is why your first example fails.
To fix it, use
foo True b = b + 2
foo _ x = id x
As you see, both equations have the same number of arguments.
Multiple equations involving pattern matching are translated into case expressions. In your case foo
gets translated roughly as
foo a b = case a of
True -> b + 2
_ -> id x
Both (all) branches of the case
must have the same type, thus you first example which would be translated as
foo a b = case a of
True -> b + 2
_ -> id
is wrong because the branches have different types.
Of course, this is hand waving, the actual things happening behind the scenes are more complicated