The most common way to establish a TCP connection is using a 3-way handshake consisting of:
But that is not the only way to establish a TCP connection. In order to establish a TCP connection each side has to send a SYN which the other side has to ACK, but it is not required that one party combines SYN and ACK in a single packet. A 4-way handshake is equally possible in which each endpoint sends a SYN and then each endpoint sends an ACK.
One use case for this 4-way handshake is for establishing a connection between a pair of hosts which are both behind a firewall. This can be useful if you are running peer-to-peer applications on a network protected by a firewall. Each endpoint will send a SYN and re-transmit it until a response is received. This means the firewall at each end of the connection will see the local endpoint sending out SYN packets, and once it has seen such an outgoing packet it will allow SYN and ACK packets from the other end to come through. (Though this method works with both TCP and UDP in practice it is rarely used with TCP.)
What all of this means to your scenario is that if an application create a TCP socket and binds it to a local IP address and port number and then attempts to connect to the same IP address and port number, the TCP layer will first generate a SYN packet which is delivered to itself and then respond to that with an ACK which is also delivered to itself.
The outcome is that it is possible for a TCP socket to be connected to itself and to the TCP layer this looks like a 4-way handshake.
I don't know whether there is any useful purpose for such a TCP socket connected to itself, but that's what would produce a connection like the one in your case.