Obstacle clearance and climb are two different things.
the flap setting you will chose for obstacle clearance depends on the distance of the obstacle from your brake release point and the height of the obstacle.
Assume an obstacle close to the liftoff end of the runway. Here a higher flap setting will allow me to lift off early and clear the obstacle whereas with a lower setting, I may not be able to clear.
Now for an obstacle far away from the runway but a high one, a lower flap setting will give me a better climb although a longer takeoff run and thus better clearance as compared to a higher flap setting.