There is no purpose, just convenience, and you may use any code you like.
kyodake's answer is correct, but it's also rather MBR-centric. Under
GPT, the same principles apply -- that is, a partition type code
identifies the intended purpose of a partition. The difference is that
GPT type codes are 128-bit GUIDs, vs. the 8-bit codes used under MBR.
The nature of GUIDs means that it's not necessary to register codes
with a central authority to avoid collisions; two GUIDs are
statistically very unlikely to be identical by accident.
AFAIK, there is no official repository of GPT type codes, but they are
documented on the Wikipedia page about
GPT.
One disadvantage of GPT type codes is that, as GUIDs, they're long and
awkward -- for instance, 0FC63DAF-8483-4772-8E79-3D69D8477DE4 for
Linux filesystem data, vs. 0x83 for the MBR equivalent. Thus, most
tools for partitioning GPT disks use some form of "shorthand" or
"natural-language translation" in their user interfaces. I'm the
author of GPT fdisk, and as my goal in writing it was to create
something that was as similar to (MBR) fdisk as possible, I took the
approach of using MBR codes as a base; however, because the
correspondence between GPT and MBR type codes isn't 1:1, I multiplied
the MBR type codes by 0x100 to get the GPT equivalents. Thus, MBR's
0x83 became 8300. This also enables related follow-on codes that don't
exist in MBR, such as 8301, 8302, etc. These codes are easy to use for
people who are already familiar with the MBR equivalents, but they're
admittedly arbitrary for people who don't know the MBR codes.
Internally, GPT fdisk translates these codes to GUIDs. You can see the
actual GUIDs by viewing detailed partition information (via the i
option in gdisk, for instance). You can also enter an arbitrary GUID
rather than use the GPT fdisk four-character codes, if you like or if
you need to use a code that GPT fdisk doesn't support.
Other tools use other approaches. The libparted library (and thus
parted, GParted, and other tools based upon libparted) translates
some type codes to "flags" and completely hides other codes. This helps simplify things for some users, but it renders some tasks
impossible -- for instance, you can't set an arbitrary type code with
anything based on libparted. OS X's Disk Utility translates known
GUIDs to plain-text descriptions. (IIRC, when you create a partition
it sets an appropriate type code based on the filesystem created in a
partition, similar to what GParted does.)
For the most part, Linux doesn't use type codes, for either MBR or
GPT. That is, you can put your standard Linux filesystem on a (GPT
fdisk) 8300 partition, or use 0700 (as was common in the past), or
assign your own random GUID. Similar comments apply to RAID, LVM,
swap, and other partition types. There are a few exceptions to this
rule, though. For one, distribution installers often look at and set
type codes, so you may need the right type code on a partition before
it will be used properly. Another exception is that systemd is
starting to make use of type codes as a fallback if /etc/fstab isn't
properly configured. (That's where most of GPT fdisk's 830x codes
originate -- they're part of the Discoverable Partitions
Specification,
which is a Freedesktop/systemd initiative.) Currently, Ubuntu is just
using the main Linux filesystem type code (8300 in GPT fdisk) for
filesystems, plus the appropriate codes for LVM, RAID, swap, etc. One
big exception to the "Linux doesn't use type codes" rules is the BIOS
Boot Partition code (21686148-6449-6E6F-744E-656564454649; ef02 in GPT
fdisk or the bios_grub flag in libparted). This type code identifies
a partition used by GRUB, and when you run grub-install, GRUB will
install part of itself to that partition. If you install GRUB on a
BIOS-booting system with a GPT disk, a BIOS Boot Partition must
normally be present. (There are ways around this rule, though.) More
importantly, if you mistakenly set this type code on the wrong
partition, that partition will be damaged when you install GRUB!
I've seen quite a few people make that mistake in various online
forums.
Where type codes become more important is when dealing with other
OSes. Windows and OS X, for instance, tend not to touch partitions
with type codes they don't recognize. Their list of type codes
excludes common Linux-specific type codes, so using a Linux-specific
type code helps reduce the risk that Windows or OS X will trash your
Ubuntu installation. These OSes don't care if you use the GPT fdisk
8300 or fd00 code, though. Problems can arise if you use codes that
are recognized by these other OSes. For instance, at one time the
Linux filesystem type GUID (0FC63DAF-8483-4772-8E79-3D69D8477DE4) did
not exist. I created it and pushed it into both my own GPT fdisk and
libparted because the common practice of using the "Microsoft Basic
Data" type code (EBD0A0A2-B9E5-4433-87C0-68B6B72699C7) was causing
problems in dual-boot setups. Specifically, certain Windows tools
would think the Linux partition was a damaged or un-initialized
Windows partition and offer to prepare it. User error at this prompt
would be disastrous. See this page of
mine for more on
this subject.