"It’s upside but looks to be a feeder or nester of some sort, attached to the top of the fence by previous owner. What is this thing?"
A: "It’s for bees, particularly Mason bees."
The polystyrene balls are used for insulation between the walls. After time they will come out during windy weather.