The house came with a completely finished (drywall ceilings and walls,
carpeted floors) basement, except for the utility room.

The basement was put in by a prior owner and it was a contra deal and
basis what I see , done without permits. The problem is with the toilet
in the basement as it is sits on a 6 or 8 inch riser.

With the kids gone we are thinking of selling and everyone tells us we
need to get rid of the riser under the toilet.

The pipe from the toilet runs into the adjacent closet and we lifted the
false floor to see what we were up against and what we found is in the
attached picture (hope it comes through).

The vertical pipe comes from the bathroom on the second floor.

I have lots of questions...

1) will the plumbing code even allow a toilet and lav to be connected to
the pipe from the second floor?

2) Is there enough room in the closet to put the necessary fittings in
to lower the toilet?

3) any idea what might have caused them not to put the pipe under the
concrete?

I won't be doing this work as it is out of my league. I will be bring
in a plumber to do it and get the requisite permits. All I am really
trying to do at this point is determine if it is possible to fix it
without having to destroy the basement.

They make back flush toilets were the waste line can be roughed in 4" above the finish floor. The toilet sits on the floor but flushes out the back. What I can't see is if the toilet and sink are vented properly.

The stack serves just the 2nd floor main bathroom. All of the other bathrooms have separate stacks.

Venting, I have no idea as the entire basement, including the bathroom is dry walled..

The distance from the center of the toilet outlet pipe to the center of the stack is 51".

The TOP of the drain pipe in the ground is 5" below the top of the concrete floor or about 2.5 " below the concrete. On top of the concrete there is a 2 x 4 on its side with a 3/4" plywood sub-flooring on it.

As for the 'hack" comment, The entire finished area of the basement has 3, count em, 3 electrical outlets. They are so cheap and easy to put in when the walls are open and so expensive and difficult to put in when they are closed.

The sad part is that this bathroom is heavily used (my office used to be in the basement) and it has given us zero problems in 20 years.

1) will the plumbing code even allow a toilet and lav to be connected to
the pipe from the second floor?

How it is done determines its legality, not IF it can be done.

2) Is there enough room in the closet to put the necessary fittings in
to lower the toilet?

No. the tee for the bathroom is sitting on top of the lateral main so it is as low as possible. The connection would have to be made somewhere in the horizontal piping. And, again, it would have to be done properly.

3) any idea what might have caused them not to put the pipe under the
concrete?

They did not have enough room given the connection they made. They did it "quick and dirty", not "properly".

I installed a sanaplus toilet that worked very well. The night after I installed it the owner had a Christmas party in 2010 with 3,000 guests. It worked flawlessly he said and is still working as of a month ago. Not sure if it could help you but the outlet of the toilet is well above the floor and it has a macerating pump inside a container that will pump the waste through a 3/4" pvc pipe. There are heavy restrictions on routing the discharge line.........it must be done as directed.