I believe it's because the way you've constructed your CASE statement is testing the result of the lead() function against null for equality. Instead of using a construction like this:
case x when null then 1 else 0 end
Try this:
case when x is null then 1 else 0 end