The primary function of a BPDU is to prevent loops in network topologies by sharing information across all switches within a network, enabling them to create a stable, loop-free spanning tree structure.