I don't know if it is only the case if a pufferfish swims in an aquarium made of glass or if it can attack through any block, however I think this is a bug.
Related issues
duplicates
Attachments
Comments

Can you include a screenshot? Through what kind of wall does it attack you, through a corner / diagonal wall or through a straight wall without any corners?

Seems to me like they attack through step blocks.
In my screenshot; I have steps going up through an aquarium surrounded by glass. They don't seem to be able to attack through the solid glass, but in this specific corner here I get hit with the poison debuff when they are also in that corner.

Duplicate of MC-2310