Why would a pilot fly a plane (a Piper PA-28, N41622) like this? This was around 18:00 Eastern time at Pensacola, Florida (PNS) on October 20, 2022. This plane shows as "Private Owner" in FlightRadar24 and "Vy Aviation LLC" on the FAA database. It makes several flights (most under 1 hour) per day.
The likely explanation is that the pilot was just making room for another aircraft. If a plane stops in the air, it stalls and falls, so planes can't (shouldn't in normal operation at least) stop in place. Think of them like a shark, which dies if it stops moving "forward" through the medium it is in. The next best thing for a plane trying to hold its position is to just circle and stay in approximately the same place.
The square box you see with one side being a runway is a traffic pattern, which could have other planes trying to fit in in front of them. An example of this would be if a plane was making a straight in approach to the same runway while this plane was in the pattern. So to make space for the other plane to land first, the plane in the pattern just did a circle or two in place, to "pause" or "stop" where they were to yield to other traffic, without actually stopping (and thus falling from the sky).
Note that the PA-28 (Piper Cherokee) is commonly used as a training aircraft -- think of it possibly as the Piper version of the popular Cessna 172 trainer aircraft. Likely, this was someone practicing landings. Unless this flight happened from 0500Z-1130Z (very early in the morning - midnight to 6:30 AM if I'm doing the math right), they would have been operating under the direction of a ATC controller, who would likely have a training flight give way to commercial traffic, leading them to being told to circle to make way.
You can go back and look at the traffic that was in the area, according to ADSB, at https://globe.adsbexchange.com/?replay=2022-10-20-21:12&lat=30.472&lon=-87.166&zoom=13.2
IFR holding patterns, whether waiting for a runway or waiting for other traffic to clear when en route, tend to be ovals, although they can be distorted by wind. The standard holding pattern is straight for 1 minute, right-hand rate 1 turn 180 degrees, straight (in the opposite direction) for 1 minute, then another right-hand rate 1 turn 180 degrees.
The PA-28 looks like it is waiting, though. It looks like it is doing circuits and is interrupted by a stretch 737 coming in for a straight-in approach and landing. It lands, then a helicopter and another commercial flight lands almost simultaneously, then a C-172 goes off and circles over the bay bridge while a Airbus A319 does a straight-in approach.
That's a really busy airport, and the controller must be working hard to manage all the different types and speeds at the same time.
When I was student pilot (in a PA-28-150), doing circuits in a small city airport (pop abt 350,000), a DC-8 was also doing circuits and the controller finally told me that he couldn't accommodate my circuits while the big bird was also in the pattern, even though there was room for both left-hand and right-hand circuits at that airport.
Pilot training often involves flying in circles. Since airplanes are controlled in three dimensions, flying in a circle with reference to the ground requires a significant level of skill when you consider that the wind will blow the plane off course and the amount of vertical lift generated by the wings changes as the airplane banks.