How to prevent weapons from penetrating the wall?

Add a collision shape to your weapon and in Blueprints you can check if your weapon is overlapping with any meshes. If it is then play weapon holstering animation in character.