I'm using Amazon Linux AMI, which seems to be some RHEL or CentOS offshoot. I've read that it should be binary compatible with RHEL. My question is: is there any advantage to compile a package from source as opposed to using the RHEL or CentOS repos (as they should work too)?
In theory compiling your own source could take advantage of particular compiler optimizations that leverage your hardware. In practice for most applications it doesn't make a tangible difference - particularly when compared to the issues associated with dependencies, updates, testing, etc. This advantage also presupposes a compiler that can optimize for the features in question which is by no means a given.
There's a semi-famous quote by Donald Knuth:
"Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%."
At this point rolling your own binaries for the purposes of performance would definitely fall into this category. There are times when particular features that aren't in distributions might be needed (for example) but these cases should be few and far between.
There are disadvantages in as much as the official packages are tested, supported and security patches are backported to them. By compiling your own you are stepping outside of this network and at the very least not have to rely on more than one maintainer group to supply patches.
Compiling From source gives you more recent version than from repositories,it might include some bug fixes. but its not a best security practice to install compilers on production servers.
Building from source usually gets you the latest version and you can try beta versions as well. However, using packages gets you well tested and stable versions. Depends on your needs.
By compiling you can optimize for your hardware, as others also said, or enable features not in the binary packages.
But having custom packages compiled from source can be harder to maintain. You have to check for updates, and security issues by yourself and compile the new version when needed.