The first command creates a file with seven lines of text. This data is used by the SO answer to illustrate the effect of the sed command, and it is written to a file called file.
Given a shell that understands $'...' ("C-strings") and that you use GNU sed (to understand d} as d;}), the second command returns the last line from the test data file on standard output and removes it from the file, backing up the original data in file~ (backing up the original data to file~ is what -i~ does).
In the SO answer, the sed editing script is written on the command line as
\$$'{w/dev/stdout\n;d}'
This is a literal $, followed by a "C-string", $'{w/dev/stdout\n;d}'. The C-string quoting means \n will be expanded to a literal newline, which gives
${w/dev/stdout
;d}
... which is a sloppy way of writing the sed script
$ {
w /dev/stdout
d
}
This sed editing script passes all but the last line through unchanged to the output (which goes into the file file since the -i option is used).
The last line is written to /dev/stdout rather than to the default output (which is file in this case) using the w command, and then deleted using d.
The effect is that all lines but the last remain in (are written back to) file while the last line is produced on standard output (which will be connected to your terminal).