there are other factors. The issue is when later CPUs are issued for the same physical socket as older ones, the newer CPUs often use an updated electrical "revision" of the socket specification with features not available on older motherboards using the same physical (but older revision) socket. Often the new CPUs will use lower voltages not supported on older motherboards or use pins on the socket that the older motherboards didn't assign and a different set of CPU support chips on the motherboard. For minor revisions sometimes a motherboard BIOS update is all that is required to support a newer CPU.
For 1151 socket there were 2 major revisions....
(From: https://levvvel.com/lga-1151-cpu-list/ ):
LGA 1151 revision 1 vs revision 2
LGA 1151 revision 1 supports Skylake and Kaby Lake CPUs. This means youll have to look towards revision 2 if you want to get your hands on some of the newest Intel CPUs, like some of the Intel Core i9 processors. Most motherboards with the LGA 1151 revision 1 socket only support DDR4 memory but there are a few with DDR3(L) support. This socket is compatible with Intel 100 and 200 chipset series, including H110, B150, Q150, B250, H270, and others.
LGA 1151 revision 2 supports Coffee Lake CPUs and its compatible with 8th and 9th generation CPUs that use the 300 series chipsets from Intel, including H310, B360, Z370, and Z390. Despite it being a revision of the original socket, its physically the same and compatible with the first revision. However, there are some pin reassignments to add more power lines that would support 6-core and 8-core CPUs.
Despite physical compatibility, there is no backward compatibility between the two revisions. The cause of this is a relocated processor detection pin. This means that you cant use the revision 1 socket for 300 series chipsets and you cant use revision 2 for 100 and 200 series Intel chipsets. This means you should be extra careful when buying a motherboard with an LGA 1151 socket. Intel doesnt actually recognize the two revisions (formally) and they dont refer to them with a distinct name. However, depending on your CPU chipset, youll need to use the proper revision! Each motherboard manufacturer keeps a list of supported chipsets so you should have no problems with finding that information.
Here is the list of CPUs your motherboard supports (you may need a BIOS update to support the later ones):
https://www.gigabyte.com/Motherboard/GA-Z270XP-SLI-rev-10/support#support-cpu
Your board uses the Z270 Express Chipset so it is 1151 revision 1.