Access the name of the gnome terminal profile from the command line

This doesn't seem to be possible, however you can find out the default terminal title, so all you need to do to distinguish between tabs or profiles is to configure different default titles.

The control sequence ESC [ 2 1 t asks the terminal to insert its title on the terminal input stream. (See Xterm control sequences for more information about escape sequences for xterm and similar programs). Specifically, the terminal (if it supports this feature; gnome-terminal does) responds with ESC ] l title ESC \.

Here's a bash function that sets the variable whose name is passed as the first argument to the xterm title, if available. It times out after one second if the terminal doesn't support the feature, and returns a non-zero error code.

read_xterm_title () {
  # Clear IFS so that read doesn't do any word splitting.
  local IFS= read_xterm_title_header=
  # $1 is expected to be a parameter name. Do a crude format check.
  if [[ $1 = '' || $1 = *[!0-9_A-Za-z]* ]]; then return 120; fi
  eval $1=
  # Expect "ESC ] l title ESC \\"
  read -p $'\e[21t' -s -t 1 -r -n 3 read_xterm_title_header &&
  [[ $read_xterm_title_header = $'\e]l' ]] &&
  read -p '' -s -t 1 -r -d $'\e' $1 &&
  read -s -t 1 -r -n 1
read_xterm_title title
case $title in ...