The short answer: the post uses invalid figures to support their claim "roughly 24 percent of all Alis in Sweden have a conviction". Furthermore, they are misrepresenting what their figures actually mean.
The first figure is the number of people residing in Sweden who are named "Ali". The source for this figure is the Swedish governmental website Statistics Sweden. They explain what their figures represent:
Name statistics are based on information about people registered in the Population Register submitted by the Swedish Tax Agency to Statistics Sweden.
The way the population register works in Sweden, anyone who wants to open a bank account, work in a regular job, or get medical treatment will need to register. It is, however, still possible to live in Sweden without being registered.
If you enter "Ali" in the Statistics Sweden web-site, you get (as of today) the following results:
14 914 persons have Ali as a main first name
14 896 men have Ali as a main first name
A total of 26 115 men have Ali as a first name
18 women have Ali as a main first name
A total of 6 474 women have Ali as a first name
14 675 persons have Ali as last name
In order to come up with the figure of people named Ali from the original post (40 790), you have to add the total for men with Ali as any first name (26 115) and the total for people of any gender with Ali as a last name (14 675).
Note how the figure quoted in the original post conflates male and female name-bearers. Women who have "Ali" as their second name are excluded, but women with "Ali" as their last name are included. Using this figure to represent "people have Ali as either first name or surname" is therefore incorrect. According to Statistics Sweden, the correct number of that is 47 282 people.
The second figure comes from Lexbase, a highly controversial private service that makes use of (or exploits, depending on your personal view) the fact that most official documents need to be available to the public in Sweden. This includes court documents. There are several criticisms of the site, but the one that is perhaps most relevant is that the database contains data of anyone who has been under legal investigation in Sweden, but the outcome of a trial is only visible after users pay a registration fee to Lexbase. The Swedish Wikipedia article explains:
Även personer som friats eller vars dom inte vunnit laga kraft ger sökträffar och markeras på kartan. Typ av rättegång framgår inte av kartan, utan allt från trafikförseelser och vårdnadstvister till grov brottslighet indikeras på samma sätt. I resultatlistan från sökningar anges numera måltyp (tvistemål eller brottmål), namn, ålder och nuvarande folkbokföringsadress. Den som kostnadsfritt prenumererar på e-postuppgifter om personer i sitt närområde som förekommer i databasen får dessutom veta deras medborgarskap. Detaljer om rättegången, inklusive rättegångsutfall, framgår av de domstolshandlingar som Lexbase tillhandahåller mot en avgift.
Even people who have been freed or whose judgments have not gained legal force give search results and are marked on the map. The type of trial does not appear on the map, but everything from traffic offenses and custody disputes to serious crime is indicated in the same way. The result list from searches now specifies the target type (dispute or criminal case), name, age and current census address. Anyone who subscribes to e-mail information about people in their immediate area that is included in the database will also know their citizenship. Details of the trial, including trial results, are set forth in the court documents provided by Lexbase for a fee.
This means that being listed in Lexbase is not the same as having a criminal record, at least as far as the term is generally understood. People listed in Lexbase have been in contact with the law for whatever reason, but the charge may have been a trivial neighborhood quarrel just as well as a violent crime, and they may have been acquitted of their charges, or they may have been sentenced – they all will be listed as entries in Lexbase.
This means that unless a fee has been paid to Lexbase so that each entry could carefully be checked, the number of people listed in Lexbase does not correspond to the number of convictions. The original post misuses the figure that they claim to have obtained from Lexbase.
Note also that the Lexbase search doesn't distinguish between male and female entries – the reported number of entries will be (unlike the Statistics Sweden figure reported in the post) both men and women who have Ali anywhere in their name.
Regardless of all this, I couldn't even reproduce the number of entries that the original post reports (9 742 entries in Lexbase). As of today (November 22, 2019), if you enter "ali" as a name in their person search, the database reports 4 961 entries, as the screenshot shows:
This is clearly much smaller than the figure reported in the original post. It may be possible that the number retrieved from Lexbase was larger at the time the original author made the post, but given that old entries are not purged from Lexbase, this isn't very probable.
So, to wrap this mess up: The conclusion that "roughly 24 percent of all Alis in Sweden have a conviction" is wrong:
The number of people called Ali is, according to Statistics Sweden, 47 282 and not 40 790, as the post claims. Their figure approximates the number of men who are named Ali, but it also includes women with Ali in their last name.
Entries in Lexbase do not represent people with criminal records, but people who have been involved in legal proceedings. The entries include both men and women.
The number of entries in Lexbase for the name Ali is currently 4 961, not 9 742 as the post claims.
If you still want to relate the number of entries for the name in Lexbase to the number of people with the name Ali in Sweden, this will give you a value of 10.5%, which is way off the "nearly a quarter" that the post claims.