Your first issue is that you are using the_field(). the_field() echoes the value. You need to use get_field(). doing this echo the_field(...)
is like doing this echo(echo get_field(...))
Using get field this should work
echo ucwords(strtolower(get_field('custompagetitle')));